This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/76732] GCC should warn on repeated initializer for same array element / struct member.
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 15 Aug 2016 10:51:06 +0000
- Subject: [Bug c/76732] GCC should warn on repeated initializer for same array element / struct member.
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-76732-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=76732
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
GCC already warns for this (for C)
test.c:1:32: warning: initialized field overwritten [-Woverride-init]
int x[] = { [0] = 1, +3, [1] = 1 };
^
test.c:1:32: note: (near initialization for ‘x[1]’)
test.c:2:43: warning: initialized field overwritten [-Woverride-init]
struct s { int a, b; } s = { .a = 1, .a = 2};
^
test.c:2:43: note: (near initialization for ‘s.a’)
Although the output of Clang is nicer (and they also warn in C++):
prog.cc:1:32: warning: initializer overrides prior initialization of this
subobject [-Winitializer-overrides]
int x[] = { [0] = 1, +3, [1] = 1 };
^
prog.cc:1:22: note: previous initialization is here
int x[] = { [0] = 1, +3, [1] = 1 };
^~
prog.cc:2:43: warning: initializer overrides prior initialization of this
subobject [-Winitializer-overrides]
struct s { int a, b; } s = { .a = 1, .a = 2};
^
prog.cc:2:35: note: previous initialization is here
struct s { int a, b; } s = { .a = 1, .a = 2};
^
(And why does GCC have an empty line before the notes?)