Bug 540047 - Can't use labeled elements in initializers for structs with unnamed union fields
Summary: Can't use labeled elements in initializers for structs with unnamed union fields
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 12
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-11-22 02:07 UTC by Casey Dahlin
Modified: 2014-06-18 08:46 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2009-11-23 07:49:10 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Reproducer (130 bytes, text/plain)
2009-11-22 02:07 UTC, Casey Dahlin
no flags Details

Description Casey Dahlin 2009-11-22 02:07:14 UTC
Created attachment 372842 [details]
Reproducer

Description of problem:
If you try to use a struct with an unnamed union field, for example:

struct foo {
  int bar;
  union {
    int baz;
    int bam;
  };
};

And then try to statically initialize one using field labels like so:

struct foo mine = { .bar = 1, .baz = 2 };

you get:

error: unknown field ‘baz’ specified in initializer

Version-Release number of selected component (if applicable):
gcc-4.4.2-7.fc12

Steps to Reproduce:
Try compiling the attached program.
  
Actual results:
reproducer.c:13: error: unknown field ‘baz’ specified in initializer

Expected results:
Compiles. mine.bar == 1, mine.baz == mine.bam == 2

Comment 1 Jakub Jelinek 2009-11-23 07:49:10 UTC
Why do you think it is a bug?  ISO C99 designated initializers require that the identifier identifies a field in the current structure/union, which is not the case.


Note You need to log in before you can comment on or make changes to this bug.