Bug 101767 - [11 Regression] Aggregate initialization fails for struct that has both unnamed struct and union fields
Summary: [11 Regression] Aggregate initialization fails for struct that has both unnam...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.0
: P1 normal
Target Milestone: 11.3
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2021-08-03 20:18 UTC by Tee KOBAYASHI
Modified: 2022-05-12 22:24 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.3.0, 11.1.0, 12.0, 8.1.0
Known to fail: 11.2.0, 7.5.0
Last reconfirmed: 2021-08-03 00:00:00


Attachments
Repro (120 bytes, text/plain)
2021-08-03 20:18 UTC, Tee KOBAYASHI
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tee KOBAYASHI 2021-08-03 20:18:14 UTC
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)
Comment 1 Andrew Pinski 2021-08-03 20:50:42 UTC
So this is most likely caused by the patch which fixes PR 100489 so this is a regression in 10.4.0 also.
Comment 2 Andrew Pinski 2021-11-16 21:56:42 UTC
*** Bug 103290 has been marked as a duplicate of this bug. ***
Comment 3 Patrick Palka 2022-01-20 14:52:32 UTC
(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.
Comment 4 Anton Maklakov 2022-02-09 08:23:03 UTC
I've stumbled this bug as well
Comment 5 GCC Commits 2022-03-21 20:47:18 UTC
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.
Comment 6 Jason Merrill 2022-03-21 20:58:50 UTC
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.
Comment 7 GCC Commits 2022-03-22 05:18:00 UTC
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.
Comment 8 Jason Merrill 2022-03-26 23:29:06 UTC
Fixed for 11.3
Comment 9 GCC Commits 2022-05-12 21:14:32 UTC
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.
Comment 10 GCC Commits 2022-05-12 22:24:07 UTC
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.