https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103060

            Bug ID: 103060
           Summary: Argument initialization side-effects missing:
                    delegating from base constructor to inherited
                    constructor from virtual base
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

The "only for the constructor of the most-derived class, virtual bases are
initialized" wording applies only to the non-delegating case. For a delegating
constructor, the target constructor is called even if it is inherited from a
virtual base and the constructor is not for the most-derived class.

### ONLINE COMPILER LINK:
https://godbolt.org/z/h7TnGxxv7


### SOURCE (<stdin>):
struct NonTriv {
  NonTriv(int);
  ~NonTriv();
};
struct V { V() = default; V(NonTriv); };
struct Q { Q(); };
int bar();
struct A : virtual V, Q {
  using V::V;
  A() : A(bar()) { }
};
struct B : A { };
void foo() { B b; }


### COMPILER INVOCATION:
g++ -O -S -o - -xc++ -std=c++20 -


### Assembly output (snippet):
_Z3foov:
.LFB6:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        leaq    8(%rsp), %rdi
        call    _ZN1QC2Ev
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc


### OBSERVATIONS:
The constructor for the direct base is being called; the wording mechanism for
that call comes from the inherited constructor invocation. That is, GCC does
invoke the inherited constructor; however, it does not process the argument.
Clang and ICC does process the argument (and also the initialization of the
corresponding parameter).


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210721 (experimental) (GCC)

Reply via email to