https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80228
Bernd Edlinger <edlinger at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|diagnostic, rejects-valid |wrong-code --- Comment #3 from Bernd Edlinger <edlinger at gcc dot gnu.org> --- This is half fixed by r267653 B was already correctly rejected, and is invalid in C++11: $ cat x.cc struct A { int n, a[]; }; struct B { int n = 3; int a1[] = { 2, 1, 0 }; // rejected (see pr72775) } b; struct C { A a2 = { 3, { 2, 1, 0 } }; // accepted } c; struct E { A a4; E (): a4 {3, { 2, 1, 0 } } { } // accepted } e; $ g++ x.cc x.cc:6:7: error: initializer for flexible array member 'int B::a1 []' 6 | int a1[] = { 2, 1, 0 }; // rejected (see pr72775) | ^~ x.cc:11:27: error: non-static initialization of a flexible array member 11 | A a2 = { 3, { 2, 1, 0 } }; // accepted | ^ x.cc: In constructor 'E::E()': x.cc:19:24: error: non-static initialization of a flexible array member 19 | a4 {3, { 2, 1, 0 } } { } // accepted | ^ C and E are diagnosed as non-static initialization which is fine. But D is still accepted: $ cat t.cc struct A { int n, a[]; }; struct D { int n, a3[]; D (): n (3), a3 {2, 1, 0} { } // silently accepted } d; D* foo () { return new D; } void bar () { volatile D vd; } $ g++ -S -O3 t.cc $ cat t.s .file "t.cc" .text .p2align 4 .globl _Z3foov .type _Z3foov, @function _Z3foov: .LFB3: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $4, %edi <<<--- allocate only 4 byte, 16 neeeded call _Znwm movdqa .LC0(%rip), %xmm0 movups %xmm0, (%rax) addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE3: .size _Z3foov, .-_Z3foov .p2align 4 .globl _Z3barv .type _Z3barv, @function _Z3barv: .LFB4: .cfi_startproc <<<--- didn't I declare vd as volatile? ret .cfi_endproc .LFE4: .size _Z3barv, .-_Z3barv .section .text.startup,"ax",@progbits .p2align 4 .type _GLOBAL__sub_I_d, @function _GLOBAL__sub_I_d: .LFB6: .cfi_startproc movdqa .LC0(%rip), %xmm0 movaps %xmm0, d(%rip) ret .cfi_endproc .LFE6: .size _GLOBAL__sub_I_d, .-_GLOBAL__sub_I_d .section .init_array,"aw" .align 8 .quad _GLOBAL__sub_I_d .globl d .bss .align 16 .type d, @object .size d, 4 d: .zero 4 <<<--- object has only 4 bytes, 16 needed .section .rodata.cst16,"aM",@progbits,16 .align 16 .LC0: .long 3 .long 2 .long 1 .long 0 .ident "GCC: (GNU) 9.0.0 20190104 (experimental)" .section .note.GNU-stack,"",@progbits