<html>
    <head>
      <base href="http://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 --- - no zero initialization in value initialization"
   href="http://llvm.org/bugs/show_bug.cgi?id=19779">19779</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>no zero initialization in value initialization
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>kezhuw@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>struct A {
        int i;
        A() {}
    };

    struct B {
        // no user-provided constructor,
        // implicitly-declared default constructor is generated by compiler.
        A a;    
    };

    char mem[1024];
    memset(mem, 0xcc, sizeof mem);
    new (mem) B{};
    B& b = *(reinterpret_cast<B*>(mem));

Compiles it with `clang++ -std=c++11`, `b.a.i` is 0xcccccccc.


This conflicts with what C++11 says about value initialization:

— if T is a (possibly cv-qualified) non-union class type without a
user-provided constructor, then the object is zero-initialized and, if T’s
implicitly-declared default constructor is non-trivial, that constructor is
called.

Or my understanding of value initialization in C++11 is wrong ?

The example comes from
<a href="http://en.cppreference.com/w/cpp/language/value_initialization">http://en.cppreference.com/w/cpp/language/value_initialization</a> .</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>