[llvm-bugs] [Bug 37038] New: Trivial copy assignment operator overwrites members not being copied
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 6 15:25:55 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37038
Bug ID: 37038
Summary: Trivial copy assignment operator overwrites members
not being copied
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Keywords: miscompilation
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: hstong at ca.ibm.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
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:
clang++ -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 (clang++ -v):
clang version 7.0.0 (https://github.com/llvm-mirror/clang.git
f38834898ad991aec557e2a609c6b7c3b288bf10)
(https://github.com/llvm-mirror/llvm.git
433eb70569ee6379cdd5181e72b9193fdb0a39dd)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180406/6f342eda/attachment.html>
More information about the llvm-bugs
mailing list