[LLVMbugs] [Bug 19779] New: no zero initialization in value initialization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun May 18 06:13:37 PDT 2014


            Bug ID: 19779
           Summary: no zero initialization in value initialization
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kezhuw at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

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

The example comes from
http://en.cppreference.com/w/cpp/language/value_initialization .

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/20140518/19708553/attachment.html>

More information about the llvm-bugs mailing list