It's a forward of https://bugs.gentoo.org/788829 ICE report by Martin Kolleck. ICE appeared in 10.3.0 and is present in 11.1.0 and 12.0.0. 10.2.0 seems to work. Here is a simple reproducer: // cat ice.cpp union U { struct { unsigned char a; }; unsigned char b[1]; }; void f(unsigned char a) { union U u = { .a = a }; } And the crash: $ LANG=C g++ -c -o /dev/null ice.cpp ice.cpp: In function 'void f(unsigned char)': ice.cpp:14:24: internal compiler error: in get_or_insert_ctor_field, at cp/constexpr.c:3556 14 | union U u = { .a = a }; | ^ 0x5fed0e get_or_insert_ctor_field /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:3556 0x68f2a2 cxx_eval_bare_aggregate /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:4455 0x685466 cxx_eval_constant_expression /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:6675 0x688030 cxx_eval_outermost_constant_expr /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:7251 0x68b592 maybe_constant_value(tree_node*, tree_node*, bool) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:7525 0x6ab92c cp_fully_fold(tree_node*) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2146 0x6ab92c cp_fully_fold(tree_node*) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2138 0x6ab9d4 cp_fully_fold_init(tree_node*) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2167 0x82219a store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/typeck2.c:816 0x6bd08d check_initializer /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/decl.c:7080 0x6d6a8f cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/decl.c:8014 0x796139 cp_parser_init_declarator /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:21891 0x7730ae cp_parser_simple_declaration /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:14457 0x77509d cp_parser_declaration_statement /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:13592 0x7756ab cp_parser_statement /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:11822 0x776eae cp_parser_statement_seq_opt /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:12189 0x776f70 cp_parser_compound_statement /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:12138 0x794117 cp_parser_function_body /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:24080 0x794117 cp_parser_ctor_initializer_opt_and_function_body /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:24131 0x79541a cp_parser_function_definition_after_declarator /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:30068 $ LANG=C h gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/x86_64-pc-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/12.0.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/12.0.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12.0.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12.0.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12.0.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/12.0.0/include/g++-v12 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/12.0.0/python --enable-languages=c,c++,d,go,jit,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 12.0.0_pre9999 p1, commit 39671f87b2df6a1894cc11a161e4a7949d1ddccd' --disable-esp --enable-libstdcxx-time --enable-host-shared --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --enable-systemtap --enable-valgrind-annotations --enable-vtable-verify --with-zstd --enable-lto --with-isl --disable-isl-version-check --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.0.0 20210420 (experimental) (Gentoo 12.0.0_pre9999 p1, commit 39671f87b2df6a1894cc11a161e4a7949d1ddccd)
It is caused by r11-6895.
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:84fd1b5dff70cd74aee7e8b18f66959d8b8e1ce7 commit r12-954-g84fd1b5dff70cd74aee7e8b18f66959d8b8e1ce7 Author: Jason Merrill <jason@redhat.com> Date: Wed May 19 21:12:45 2021 -0400 c++: designated init with anonymous union [PR100489] My patch for PR98463 added an assert that tripped on this testcase, because we ended up with a U CONSTRUCTOR with an initializer for a, which is not a member of U. We need to wrap the a initializer in another CONSTRUCTOR for the anonymous union. There was already support for this in process_init_constructor_record, but not in process_init_constructor_union. But since this is about brace elision, it really belongs under reshape_init rather than digest_init, so this patch moves the handling to reshape_init_class, which also handles unions. PR c++/100489 gcc/cp/ChangeLog: * decl.c (reshape_init_class): Handle designator for member of anonymous aggregate here. * typeck2.c (process_init_constructor_record): Not here. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/desig18.C: New test.
The releases/gcc-11 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:0a1010428b3861464eb319c629c68cb13b9ca01e commit r11-8449-g0a1010428b3861464eb319c629c68cb13b9ca01e Author: Jason Merrill <jason@redhat.com> Date: Wed May 19 21:12:45 2021 -0400 c++: designated init with anonymous union [PR100489] My patch for PR98463 added an assert that tripped on this testcase, because we ended up with a U CONSTRUCTOR with an initializer for a, which is not a member of U. We need to wrap the a initializer in another CONSTRUCTOR for the anonymous union. There was already support for this in process_init_constructor_record, but not in process_init_constructor_union. But since this is about brace elision, it really belongs under reshape_init rather than digest_init, so this patch moves the handling to reshape_init_class, which also handles unions. PR c++/100489 gcc/cp/ChangeLog: * decl.c (reshape_init_class): Handle designator for member of anonymous aggregate here. * typeck2.c (process_init_constructor_record): Not here. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/desig18.C: New test.
The releases/gcc-10 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:a335afe208cd27cf8ee4cb028fb7769700ab6245 commit r10-9857-ga335afe208cd27cf8ee4cb028fb7769700ab6245 Author: Jason Merrill <jason@redhat.com> Date: Wed May 19 21:12:45 2021 -0400 c++: designated init with anonymous union [PR100489] My patch for PR98463 added an assert that tripped on this testcase, because we ended up with a U CONSTRUCTOR with an initializer for a, which is not a member of U. We need to wrap the a initializer in another CONSTRUCTOR for the anonymous union. For the GCC 10 branch, just remove the assert. PR c++/100489 gcc/cp/ChangeLog: * constexpr.c (get_or_insert_ctor_field): Remove assert. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/desig18.C: New test.
Fixed for 10.4/11.2/12.