This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/64480] New: List designated initializer triggers -Wmissing-field-initializers
- From: "petr.pisar at atlas dot cz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 03 Jan 2015 15:27:22 +0000
- Subject: [Bug c/64480] New: List designated initializer triggers -Wmissing-field-initializers
- Auto-submitted: auto-generated
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.