| 1 |
// PR c++/55227 |
| 2 |
// Test designated initializer for char array by string constant |
| 3 |
|
| 4 |
// { dg-options "" } |
| 5 |
|
| 6 |
struct C {char a[2];}; |
| 7 |
|
| 8 |
/* Case a, designated, unbraced, string-literal of the exact same size |
| 9 |
as the initialized char array; valid and accepted before and after. */ |
| 10 |
C a = {.a="a"}; |
| 11 |
|
| 12 |
/* Cases b,c,d, designated, braced or mimatched-size, string literal, |
| 13 |
previously rejected; "C99 designator 'a' outside aggregate initializer". */ |
| 14 |
C b = {.a=""}; |
| 15 |
C c = {.a={""}}; |
| 16 |
C d = {.a={"a"}}; |
| 17 |
|
| 18 |
/* Case e, designated char array field and braced, designated array element(s) |
| 19 |
(with GNU [N]= extension) valid and accepted before and after. */ |
| 20 |
C e = {.a={[0]='a'}}; |
| 21 |
|
| 22 |
/* Cases f,g,h, braced string literal, 'designated' within inner braces; |
| 23 |
invalid, previously accepted as positional with 'designator' ignored. */ |
| 24 |
C f = {{[0]="a"}}; // { dg-error "C99 designator .0. outside aggregate initializer" } |
| 25 |
C g = {{.a="a"}}; // { dg-error "C99 designator .a. outside aggregate initializer" } |
| 26 |
C h = {{.b="a"}}; // { dg-error "C99 designator .b. outside aggregate initializer" } |
| 27 |
|
| 28 |
char a2[][10] = { [0] = { "aaa" } }; |
| 29 |
|
| 30 |
struct D { C c; int a[8]; }; |
| 31 |
|
| 32 |
D x = { .c {.a={"a"}}, .a={1,2,3,4,5,6,7,8} }; |
| 33 |
|
| 34 |
struct A { union { int a; char c[4]; }; }; |
| 35 |
|
| 36 |
A non = { .c = "c++" }; |
| 37 |
|
| 38 |
template <class T> |
| 39 |
void t() |
| 40 |
{ |
| 41 |
C ca[] = { {.a=""}, {.a={""}}, }; |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
void u() |
| 46 |
{ |
| 47 |
return t<void>(); |
| 48 |
} |