Created attachment 51254 [details] Repro $ cat unnamed_fields.cc typedef struct { struct { int x; }; union { int y; float z; }; } S; void foo(void) { [[maybe_unused]] S a = { .x = 1, .y = 0 }; } $ g++-11.2.0 unnamed_fields.cc -c unnamed_fields.cc: In function 'void foo()': unnamed_fields.cc:17:3: error: 'S::<unnamed struct>' has no non-static data member named 'y' 17 | }; | ^ $ g++-11.2.0 -v Using built-in specs. COLLECT_GCC=g++-11.2.0 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-11.2.0/work/gcc-11.2.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/11.2.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 11.2.0 p1' --disable-esp --enable-libstdcxx-time --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 --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --without-zstd --enable-lto --without-isl --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.2.0 (Gentoo 11.2.0 p1)
So this is most likely caused by the patch which fixes PR 100489 so this is a regression in 10.4.0 also.
*** Bug 103290 has been marked as a duplicate of this bug. ***
(In reply to Andrew Pinski from comment #1) > So this is most likely caused by the patch which fixes PR 100489 so this is > a regression in 10.4.0 also. Yep, started with r12-954.
I've stumbled this bug as well
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:e3e191b4104c7d6a177f66dbb77cabf05ab63781 commit r12-7740-ge3e191b4104c7d6a177f66dbb77cabf05ab63781 Author: Jason Merrill <jason@redhat.com> Date: Fri Mar 18 14:36:19 2022 -0400 c++: designator and anon struct [PR101767] We found .x in the anonymous struct, but then didn't find .y there; we should decide that means we're done with the struct rather than that the code is wrong. PR c++/101767 gcc/cp/ChangeLog: * decl.cc (reshape_init_class): Back out of anon struct if a designator doesn't match. gcc/testsuite/ChangeLog: * g++.dg/ext/anon-struct10.C: New test.
The 10 branch patch was just removing an assert, so it didn't regress there. Fixed on trunk so far. Marking P1 for 11 branch.
The releases/gcc-11 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:b94c95fc1199bfa2c7ab577921b07ef545976cac commit r11-9677-gb94c95fc1199bfa2c7ab577921b07ef545976cac Author: Jason Merrill <jason@redhat.com> Date: Fri Mar 18 14:36:19 2022 -0400 c++: designator and anon struct [PR101767] We found .x in the anonymous struct, but then didn't find .y there; we should decide that means we're done with the struct rather than that the code is wrong. PR c++/101767 gcc/cp/ChangeLog: * decl.c (reshape_init_class): Back out of anon struct if a designator doesn't match. gcc/testsuite/ChangeLog: * g++.dg/ext/anon-struct10.C: New test.
Fixed for 11.3
The releases/gcc-10 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:846bff4d4659d9b2026da574194599f38a00cc79 commit r10-10718-g846bff4d4659d9b2026da574194599f38a00cc79 Author: Jason Merrill <jason@redhat.com> Date: Fri Mar 18 14:36:19 2022 -0400 c++: designator and anon struct [PR101767] We found .x in the anonymous struct, but then didn't find .y there; we should decide that means we're done with the struct rather than that the code is wrong. PR c++/101767 gcc/cp/ChangeLog: * decl.c (reshape_init_class): Back out of anon struct if a designator doesn't match. gcc/testsuite/ChangeLog: * g++.dg/ext/anon-struct10.C: New test.
The releases/gcc-10 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:0807111e6347778910c9cf63521b7c838effceb8 commit r10-10731-g0807111e6347778910c9cf63521b7c838effceb8 Author: Jason Merrill <jason@redhat.com> Date: Thu May 12 17:38:40 2022 -0400 Revert "c++: designator and anon struct [PR101767]" 101767 wasn't broken on the 10 branch, so it doesn't need the fix, just the test. PR c++/101767 This reverts commit 846bff4d4659d9b2026da574194599f38a00cc79.