https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68006

            Bug ID: 68006
           Summary: [6 Regression] [C++14] Incorrect aggregate
                    initialization from empty initializer list with NSDMI
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net
  Target Milestone: ---

r228925 miscompiles this program:

inline void* operator new(decltype(sizeof(0)), void* ptr) {
  return ptr;
}

struct X { int x; int y; int z = 42; };

void test_bar(X* p) {
  new(p) X{};   // Bad.
}

to:

~/gcc6/bin/g++ -std=c++14 foo.cpp -O -S -o -
        .file   "foo.cpp"
        .text
        .globl  _Z8test_barP1X
        .type   _Z8test_barP1X, @function
_Z8test_barP1X:
.LFB1:
        .cfi_startproc
        movl    $42, 8(%rdi)
        ret
        .cfi_endproc
.LFE1:
        .size   _Z8test_barP1X, .-_Z8test_barP1X
        .ident  "GCC: (GNU) 6.0.0 20151016 (experimental)"
        .section        .note.GNU-stack,"",@progbits

The construction in test_bar only initializes the member with the NSDMI - X::z
- and does not correctly initialize the other members to 0. GCC 5.1 and 5.2
both compile the program correctly:

~/gcc-5.2/bin/g++ -std=c++14 foo.cpp -O -S -o -
        .file   "foo.cpp"
        .text
        .globl  _Z8test_barP1X
        .type   _Z8test_barP1X, @function
_Z8test_barP1X:
.LFB1:
        .cfi_startproc
        movl    $0, (%rdi)
        movl    $0, 4(%rdi)
        movl    $42, 8(%rdi)
        ret
        .cfi_endproc
.LFE1:
        .size   _Z8test_barP1X, .-_Z8test_barP1X
        .ident  "GCC: (GNU) 5.2.0"
        .section        .note.GNU-stack,"",@progbits

Reply via email to