Prior to r231665 the test case below (reduced from the one for bug 69912 (flexary15.C) was rejected with the error: t.C: In function ‘void bar(const char*)’: t.C:8:38: error: too many initializers for ‘const char* [0]’ static const S t = { 1, { a, "b" } }; ^ With r231665, GCC fails with an ICE: $ cat y.C && gcc -S -Wall -Wextra -Wpedantic y.C struct S { int n; const char *a[]; }; void bar (const char *a) { static const S t = { 1, { a, "b" } }; } y.C:3:17: warning: ISO C++ forbids flexible array member ‘a’ [-Wpedantic] const char *a[]; ^ y.C: In function ‘void bar(const char*)’: y.C:8:38: warning: initialization of a flexible array member [-Wpedantic] static const S t = { 1, { a, "b" } }; ^ y.C:8:38: internal compiler error: in verify_ctor_sanity, at cp/constexpr.c:2641 0xaa9e05 verify_ctor_sanity /src/gcc/git/gcc/cp/constexpr.c:2640 0xaaa042 cxx_eval_bare_aggregate /src/gcc/git/gcc/cp/constexpr.c:2670 0xab12e0 cxx_eval_constant_expression /src/gcc/git/gcc/cp/constexpr.c:4346 0xaaa190 cxx_eval_bare_aggregate /src/gcc/git/gcc/cp/constexpr.c:2688 0xab12e0 cxx_eval_constant_expression /src/gcc/git/gcc/cp/constexpr.c:4346 0xab275e cxx_eval_outermost_constant_expr /src/gcc/git/gcc/cp/constexpr.c:4634 0xab3832 maybe_constant_init(tree_node*, tree_node*) /src/gcc/git/gcc/cp/constexpr.c:4956 0x8b3e82 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) /src/gcc/git/gcc/cp/typeck2.c:825 0x7f4aad check_initializer /src/gcc/git/gcc/cp/decl.c:6365 0x7f808c cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) /src/gcc/git/gcc/cp/decl.c:7037 0x942597 cp_parser_init_declarator /src/gcc/git/gcc/cp/parser.c:19384 0x9366d8 cp_parser_simple_declaration /src/gcc/git/gcc/cp/parser.c:12781 0x936250 cp_parser_block_declaration /src/gcc/git/gcc/cp/parser.c:12599 0x9356ce cp_parser_declaration_statement /src/gcc/git/gcc/cp/parser.c:12208 0x931e5c cp_parser_statement /src/gcc/git/gcc/cp/parser.c:10695 0x932a71 cp_parser_statement_seq_opt /src/gcc/git/gcc/cp/parser.c:11027 0x93296e cp_parser_compound_statement /src/gcc/git/gcc/cp/parser.c:10981 0x946555 cp_parser_function_body /src/gcc/git/gcc/cp/parser.c:21430 0x94671c cp_parser_ctor_initializer_opt_and_function_body /src/gcc/git/gcc/cp/parser.c:21466 0x94fabf cp_parser_function_definition_after_declarator /src/gcc/git/gcc/cp/parser.c:26254 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.
In C the test case isn't strictly conforming because it uses a non-constant initializer for a static object (for which it's rejected by GCC), and because C doesn't allow initializing objects with flexible array members. In C++ where such initializers are allowed it is meant to be accepted by G++ which also supports static initialization of flexible array members as an extension.
Confirming the ICE. $ xg++-5 -c l.cc l.cc: In function ‘void bar(const char*)’: l.cc:8:45: error: too many initializers for ‘const char* [0]’ static const struct S t = { 1, { a, "b" } }; ^
Started with r231665.
Author: jason Date: Fri Apr 21 19:26:54 2017 New Revision: 247067 URL: https://gcc.gnu.org/viewcvs?rev=247067&root=gcc&view=rev Log: PR c++/80179 - ICE with initialized flexible array member. * constexpr.c (verify_ctor_sanity): Handle flexible array members. Added: trunk/gcc/testsuite/g++.dg/ext/flexary24.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c
Author: jason Date: Wed May 31 17:52:44 2017 New Revision: 248751 URL: https://gcc.gnu.org/viewcvs?rev=248751&root=gcc&view=rev Log: PR c++/80179 - ICE with initialized flexible array member. * constexpr.c (verify_ctor_sanity): Handle flexible array members. Added: branches/gcc-7-branch/gcc/testsuite/g++.dg/ext/flexary24.C Modified: branches/gcc-7-branch/gcc/cp/ChangeLog branches/gcc-7-branch/gcc/cp/constexpr.c
Fixed for 6.4/7.2/8
Author: jason Date: Wed May 31 18:53:57 2017 New Revision: 248758 URL: https://gcc.gnu.org/viewcvs?rev=248758&root=gcc&view=rev Log: PR c++/80179 - ICE with initialized flexible array member. * constexpr.c (verify_ctor_sanity): Handle flexible array members. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/ext/flexary24.C Modified: branches/gcc-6-branch/gcc/cp/ChangeLog branches/gcc-6-branch/gcc/cp/constexpr.c