https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85271
Bug ID: 85271 Summary: Trivial copy assignment operator overwrites members not being copied Product: gcc Version: 8.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: --- In the following, the operator= used by Q's defaulted copy assignment operator for the "d" subobject is a copy assignment operator of B: that is, it does not copy the "b0" member of "d". The expected behaviour is observed when Q's copy assignment operator is explicitly defaulted after its first declaration, but not if it is explicitly defaulted on its first declaration. ### SOURCE (<stdin>): extern "C" void abort(void); struct B0 { int b0; }; struct B { B &operator=(const B &) = default; int x; }; struct D : B0, B { using B::operator=; private: D &operator=(const D &) && = default; }; struct Q { Q &operator=(const Q &) = default; D d; }; //Q &Q::operator=(const Q &) = default; Q qa, qb; int main(void) { qb.d.b0 = 42; qb = qa; if (qb.d.b0 != 42) abort(); } ### COMPILER INVOCATION: g++ -xc++ -std=c++2a -o inhtrivcpyassn - ### INVOCATION AND OUTPUT OF RESULTING EXECUTABLE: > ./inhtrivcpyassn; printf '(rc=%d)\n' "$?" Aborted ./inhtrivcpyassn (rc=134) ### EXPECTED RUN OUTPUT: (rc=0) ### COMPILER VERSION INFO: 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/8.0.1/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 gcc version 8.0.1 20180405 (experimental) (GCC)