[llvm-bugs] [Bug 25589] New: Zero initialization in delegating constructor clobbers derived-class members

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 20 14:02:05 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25589

            Bug ID: 25589
           Summary: Zero initialization in delegating constructor clobbers
                    derived-class members
           Product: clang
           Version: trunk
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hstong at ca.ibm.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

In the following, the xp member of the C object should be the null
pointer-to-member value of the appropriate type because of the
zero-initialization that takes place prior to the call to the default
constructor for C.

It appears that the zero-initialization done in the delegating constructor for
A is initializing the padding as-if it was called for a most-derived object.

Online compiler: http://melpon.org/wandbox/permlink/PF2ZvaLcCTHlAKKH

### REPRODUCTION SCRIPT:
clang++ -x c++ -std=c++11 -<<'EOF' && ./a.out
#include <cassert>
#include <cstring>
#include <new>

struct A {
   ~A() { }
   A() = default;
   A(int) : A() { }
   alignas(16) char x;
};

struct B : A {
   B() : A(0) { }
};

struct C : B {
   char A::*xp;
};

A a;

int main(void) {
   alignas(A) unsigned char blob[sizeof(A)] = { 1, 1 };
   A *ap = new (static_cast<void *>(&blob)) A(0);
   assert(std::memcmp(&a, ap, sizeof a) == 0);
   assert(!C().xp);
}
EOF


### ACTUAL OUTPUT:
a.out: <stdin>:26: int main(): Assertion `!C().xp' failed.


### EXPECTED OUTPUT:
(no assertion failure)


### COMPILER VERSION INFO (clang++ -v):
clang version 3.8.0 (trunk 253668)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/llvm-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.3
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
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/20151120/9c67f41e/attachment.html>


More information about the llvm-bugs mailing list