Bug 87032 - incorrect nested structure with union initialization
Summary: incorrect nested structure with union initialization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2.0
: P3 normal
Target Milestone: 11.0
Assignee: Marek Polacek
URL:
Keywords: ice-on-valid-code, rejects-valid
Depends on:
Blocks:
 
Reported: 2018-08-20 17:12 UTC by Vadim Sukhomlinov
Modified: 2021-08-24 21:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-07-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim Sukhomlinov 2018-08-20 17:12:19 UTC
For the code:
/**************/
struct f1 {int x,y;};
struct f2 {int x,y,z,t;};

struct T {
const char * name;
union {
       struct f1  fn1;
       struct f2  fn2;
} d;
};

extern "C" void p(struct T);

int main(){
p({"%x",{.fn2={1,2,3,4}}});
}
/******************/

gcc 7.3 generates:
<source>: In function 'int main()':

<source>:15:26: internal compiler error: in reshape_init_class, at cp/decl.c:5802

 p({"%x",{.fn2={1,2,3,4}}});

                          ^

mmap: Invalid argument

gcc 8.1/8.2:
<source>: In function 'int main()':

<source>:15:26: error: could not convert '{"%x", {{1, 2, 3, 4}}}' from '<brace-enclosed initializer list>' to 'T'

 p({"%x",{.fn2={1,2,3,4}}});

                          ^

Compiler returned: 1

At the same time Clang starting 3.1 and higher generates valid code.
Testing done using https://godbolt.org/
Comment 1 Marek Polacek 2020-07-23 18:08:45 UTC
Fixed by r269371.
Comment 2 GCC Commits 2020-09-17 20:15:01 UTC
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:4f0aa5b051c0d3e81478bcb495e4e072b2d9827d

commit r11-3268-g4f0aa5b051c0d3e81478bcb495e4e072b2d9827d
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Sep 17 15:31:50 2020 -0400

    c++: Add tests for fixed PRs.
    
    Bugzilla inspection turned up a bunch of old(er) PRs that have been
    fixed.  Let's include them not to regress in the future.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/87530
            PR c++/58156
            PR c++/68828
            PR c++/86002
            PR c++/91525
            PR c++/96223
            PR c++/87032
            PR c++/35098
            * g++.dg/cpp0x/move-return4.C: New test.
            * g++.dg/cpp0x/vt-58156.C: New test.
            * g++.dg/cpp2a/concepts-pr68828.C: New test.
            * g++.dg/cpp2a/concepts-pr86002.C: New test.
            * g++.dg/cpp2a/concepts-pr91525.C: New test.
            * g++.dg/cpp2a/constexpr-indeterminate1.C: New test.
            * g++.dg/cpp2a/desig17.C: New test.
            * g++.dg/ext/attrib62.C: New test.
Comment 3 Marek Polacek 2020-09-17 20:17:49 UTC
Fixed.