The fixes test out, as does the FIXME that's fixed based on the fixes...

Note that the bug causes bogus rejection of any designated initialization
of char array from a string literal, except for the singular case where the
string literal initializer size exactly matches the target char array size
and is not enclosed in optional braces:

  typedef struct
  C { char id[4]; } C;

  C a = {.id = "abc"};   // g++ accepts iff sizeof(C::c) == sizeof("abc")

  C b = {.id = {"abc"}}; // g++ rejects valid (gcc accepts)
  C c = {.id = "a"};     // g++ rejects valid (gcc accepts)

I'd expect this to be common in C code bases, so the bug would be hit in
any attempt to compile with g++. From the bugzilla comments, it seems that
the following 'workaround' is being used:

  C d = {{.id = "a"}};   // g++ accepts invalid (gcc rejects)

which 'works' in this case but is completely borked, consider:

  struct name {char first[32], second[32], third[32];};
  name DMR {{.first = "Dennis"}, {.third = "Ritchie"}};

Only g++ accepts, ignores the designators, interprets as positional,
and generates correspondingly invalid output:

DMR:
        .string "Dennis"
        .zero   25
        .string "Ritchie"
        .zero   24
        .zero   32

Reply via email to