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

            Bug ID: 94225
           Summary: C18 conformance for structure implicit initialization
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dje at gcc dot gnu.org
  Target Milestone: ---

Example 12 in section 6.7.9 of the C18 standard demonstrates that implicit
initialization does not override prior explicit initialization.  The following
is the example code with error checking added.

$ cat example12.c
#include <stdio.h>

struct T {
  int k;
  int l;
};
struct S {
  int i;
  struct T t;
};

struct T x = {.l = 43, .k = 42, };
int main(void)
{
  struct S l = { 1, .t = x, .t.l = 41, };
  if (l.t.k != 42)
    fprintf(stderr, "l.t.k is %d instead of 42\n", l.t.k);
}

$ ./xgcc -B./ -std=gnu1x example12.c
$ ./a.out
l.t.k is 0 instead of 42
$

Reply via email to