https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82283

            Bug ID: 82283
           Summary: Wrong warning with -Wmissing-field-initializers
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: etienne.doms at gmail dot com
  Target Milestone: ---

See the following code:

/*
 * gcc bug.c -Wextra -c
 */

struct A {
    int *a;
    int b;
};

union B {
    struct A a;
};

union B data1 = {
    .a.a = & (int) { 0 },
    .a.b = 0
};

union B data2 = {
    .a.b = 0,
    .a.a = & (int) { 0 }
};

This triggers to the following warnings, reported on "data1" initialization:

bug.c:16:5: warning: missing initializer for field 'b' of 'struct A'
[-Wmissing-field-initializers]
     .a.b = 0
     ^
bug.c:7:9: note: 'b' declared here
     int b;
         ^

Interestingly, there is no warning on "data2" initialization, which should be
exactly the same.

Got this issue on the Ubuntu 16.04 stock GCC (5.4.0), the issue is also present
with GCC 7.2.

Reply via email to