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

--- Comment #6 from Yann Droneaud <yann at droneaud dot fr> ---
Found this one on stack overflow[1], and I find it a bit embarrassing:

    struct {
      struct {
        int a;
        int b;
      } c[1];
    } d = {
        .c[0].a = 1,
        .c[0].b = 1,
    };

Results in the following warning:

    <source>:7:8: error: missing initializer for field 'b' of 'struct
<anonymous>' [-Werror=missing-field-initializers]
        7 |        .c[0].b = 1,
          |        ^
    <source>:4:9: note: 'b' declared here
        4 |     int b;
          |         ^
    cc1: all warnings being treated as errors
    Compiler returned: 1

See https://godbolt.org/z/zGqM7C

GCC emits a warning about a field missing an initializer despite being
obviously explicitly initialized.

If the present but missing initialization is removed:

    struct {
      struct {
        int a;
        int b;
      } c[1];
    } d = {
        .c[0].a = 1,
    };

GCC complains, incorrectly, about a missing initializer, as described in
previous comments:

    <source>:8:1: error: missing initializer for field 'b' of 'struct
<anonymous>' [-Werror=missing-field-initializers]
        8 | };
          | ^
    <source>:4:9: note: 'b' declared here
        4 |     int b;
          |         ^
    cc1: all warnings being treated as errors
    Compiler returned: 1

See https://godbolt.org/z/8NRwo5

[1]
https://stackoverflow.com/questions/22194935/wmissing-field-initializer-when-using-designated-initializers

Reply via email to