POC: --- struct { int mem [ ] ; int b ; } s = {1}; --- run script: --- g++ -o poc poc.cpp --- g++ version: --- g++ (GCC) 10.0.1 20200214 (experimental) --- Stack dump: --- poc.cpp:4:10: internal compiler error: in output_constructor_regular_field, at varasm.c:5255 4 | } s = {1}; | ^ 0x836f9b output_constructor_regular_field ../../gcc/varasm.c:5255 0x836f9b output_constructor ../../gcc/varasm.c:5536 0x1311bcd output_constant ../../gcc/varasm.c:4908 0x1311bcd assemble_variable_contents ../../gcc/varasm.c:2148 0x1317158 assemble_variable(tree_node*, int, int, int) ../../gcc/varasm.c:2327 0x131a9d9 varpool_node::assemble_decl() ../../gcc/varpool.c:587 0xbe50cc output_in_order ../../gcc/cgraphunit.c:2564 0xbe50cc symbol_table::compile() ../../gcc/cgraphunit.c:2801 0xbe733c symbol_table::compile() ../../gcc/cgraphunit.c:2717 0xbe733c symbol_table::finalize_compilation_unit() ../../gcc/cgraphunit.c:2984 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. ---
This is invalid code. The variable length field should be detected as not last field in the struct.
Started with r6-5791-g7e9a3ad30076ad8a. Before the revision we accepted the code.
GCC rejects the code when the struct has a name: $ cat t.C && gcc -S -Wall -Wextra t.C struct S { int mem [ ] ; int b ; } s = {1}; t.C:2:9: error: flexible array member ‘S::mem’ not at end of ‘struct S’ 2 | int mem [ ] ; | ^~~ t.C:4:9: warning: missing initializer for member ‘S::b’ [-Wmissing-field-initializers] 4 | } s = {1}; | ^
Patch: https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00995.html
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>: https://gcc.gnu.org/g:dbfba41e95d1d93b17e907b7f516b52ed3a3c415 commit r10-6789-gdbfba41e95d1d93b17e907b7f516b52ed3a3c415 Author: Martin Sebor <msebor@redhat.com> Date: Fri Feb 21 10:45:56 2020 -0700 PR c++/93753 - ICE on a flexible array followed by a member in an anonymous struct with an initializer gcc/cp/ChangeLog: PR gcov-profile/93753 * class.c (check_flexarrays): Tighten up a test for potential members of anonymous structs or unions. gcc/testsuite/ChangeLog: PR gcov-profile/93753 * g++.dg/ext/flexary36.C: New test. * g++.dg/lto/pr93166_0.C: Make struct with flexarray valid.
Fixed in GCC 10.0. The fix should be backported.
The releases/gcc-9 branch has been updated by Martin Sebor <msebor@gcc.gnu.org>: https://gcc.gnu.org/g:9ca4280a921b0094c7ef131c5c8a63b451ab9a05 commit r9-8342-g9ca4280a921b0094c7ef131c5c8a63b451ab9a05 Author: Martin Sebor <msebor@redhat.com> Date: Thu Mar 5 09:37:25 2020 -0700 Backport fix for PR c++/93753 from trunk. gcc/cp/ChangeLog: Backport from trunk. 2020-02-21 Martin Sebor <msebor@redhat.com> PR c++/93753 * class.c (check_flexarrays): Tighten up a test for potential members of anonymous structs or unions. gcc/testsuite/ChangeLog: Backport from trunk. 2020-02-21 Martin Sebor <msebor@redhat.com> PR c++/93753 * g++.dg/ext/flexary36.C: New test.
The GCC 8 branch is being closed, fixed in GCC 9.3.