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

            Bug ID: 64480
           Summary: List designated initializer triggers
                    -Wmissing-field-initializers
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petr.pisar at atlas dot cz

This code:

struct lower {
    char *foo;
    char *bar;
};

struct upper {
    struct lower inner;
};

int main (void) {
    struct upper u = {
        /* This triggers -Wmissing-field-initializers warning */
        .inner.foo = "Foo",
        .inner.bar = "Bar",

        /* While this passes: 
        .inner = {
            .foo = "Foo",
            .bar = "Bar",
        },
        */
    };

    (void)u;

    return 0;
}


Triggers warning about initialized lower.bar field:

$ gcc -Wall -Wextra -std=c99 -O0 -g test.c
test.c: In function ‘main’:
test.c:14:9: warning: missing initializer for field ‘bar’ of ‘struct lower’
[-Wmissing-field-initializers]
         .inner.bar = "Bar",
         ^
test.c:3:11: note: ‘bar’ declared here
     char *bar;
           ^

If I change to initialization from the list form (.inner.foo=) to nested
(.inner={.foo=}), then it passes. The change is commented out in the quoted
code.

I think the list syntax is valid per C99, 6.7.9 Initialization grammar.

Reply via email to