This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/64480] New: List designated initializer triggers -Wmissing-field-initializers


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]