<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Zero initialization in delegating constructor clobbers derived-class members"
   href="https://llvm.org/bugs/show_bug.cgi?id=25589">25589</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Zero initialization in delegating constructor clobbers derived-class members
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hstong@ca.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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: <a href="http://melpon.org/wandbox/permlink/PF2ZvaLcCTHlAKKH">http://melpon.org/wandbox/permlink/PF2ZvaLcCTHlAKKH</a>

### 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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>