This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/78079] New: implicit initialization overrides explicit designated initializer
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 22 Oct 2016 20:55:07 +0000
- Subject: [Bug c/78079] New: implicit initialization overrides explicit designated initializer
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78079
Bug ID: 78079
Summary: implicit initialization overrides explicit designated
initializer
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In C11 DR 413
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm#dr_413) the
committee's resolution clarifies by adding an example the intent already
present in the standard that implicit initialization of struct members doesn't
override their explicit initialization.
When compiled using GCC the added example (below) aborts at runtime when it is
expected to run successfully to completion. (Clang does the right thing and
its output might help illuminate why. See below.)
$ cat b.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall
-Wextra -Wpedantic b.c && ./a.out
typedef struct {
int k;
int l;
int a[2];
} T;
typedef struct {
int i;
T t;
} S;
T x = {.l = 43, .k = 42, .a[1] = 19, .a[0] = 18 };
int main (void)
{
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
if (l.t.k != 42) __builtin_abort ();
}
Aborted (core dumped)
$ /build/llvm-trunk/bin/clang -Wall -Wextra -Wpedantic b.c && ./a.out
b.c:16:30: warning: subobject initialization overrides initialization of other
fields within its enclosing subobject [-Winitializer-overrides]
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
^~~~~~~
b.c:16:25: note: previous initialization is here
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
^
b.c:16:41: warning: subobject initialization overrides initialization of other
fields within its enclosing subobject [-Winitializer-overrides]
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
^~~~~~~~~~
b.c:16:25: note: previous initialization is here
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
^
2 warnings generated.