Bug 40136 - Initializing a union whose first member is an anonymous struct
Summary: Initializing a union whose first member is an anonymous struct
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.1
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-13 23:21 UTC by Mark Leone
Modified: 2009-05-14 00:42 UTC (History)
1 user (show)

See Also:
Host: i686-apple-darwin9-gcc-4.0.1
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Leone 2009-05-13 23:21:11 UTC
Not sure if this is a bug or a standards interpretation issue.  Consider the following union, whose first member is an anonymous struct:

union Foo {
    struct { float a,b,c; };
    const char* x;
};

icc (10.1) permits initialization of the first member of the union:

Foo foo = { .0f, .0f, .0f };

gcc (4.0.1) doesn't permit that, but does permit the following, which I believe should not be accepted:

Foo foo = { "foo" };
Comment 1 H.J. Lu 2009-05-14 00:42:00 UTC
4.0 branch is closed. Gcc 4.1.2 gave

[hjl@gnu-3 tmp]$ cat u.cc
union Foo {
    struct { float a,b,c; };
    const char* x;
};

Foo foo = { .0f, .0f, .0f };
Foo foo1 = { "foo" };
[hjl@gnu-3 tmp]$ gcc -c u.cc
u.cc:7: error: cannot convert ‘const char*’ to ‘float’ in initialization
[hjl@gnu-3 tmp]$