| 1 |
/* Test C23 storage class specifiers in compound literals: invalid code. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
int *p = &(register int) { 0 }; /* { dg-error "file-scope compound literal specifies" } */ |
| 6 |
|
| 7 |
int v; |
| 8 |
|
| 9 |
void |
| 10 |
f () |
| 11 |
{ |
| 12 |
int *q = &(thread_local int) { 0 }; /* { dg-error "compound literal implicitly auto and declared" } */ |
| 13 |
int *pc = &(static int) { v }; /* { dg-error "not constant" } */ |
| 14 |
int *pt = &(static thread_local int) { v }; /* { dg-error "not constant" } */ |
| 15 |
&(register int) { 0 }; /* { dg-error "address of register compound literal requested" } */ |
| 16 |
struct s { int a, b; }; |
| 17 |
&((register struct s) { 1, 2 }.b); /* { dg-error "address of register compound literal requested" } */ |
| 18 |
} |
| 19 |
|
| 20 |
int *s = &(static static int) { 0 }; /* { dg-error "duplicate" } */ |
| 21 |
|
| 22 |
void |
| 23 |
g () |
| 24 |
{ |
| 25 |
(void) (register register int) { 0 }; /* { dg-error "duplicate" } */ |
| 26 |
(void) (static static int) { 0 }; /* { dg-error "duplicate" } */ |
| 27 |
(void) (static thread_local thread_local int) { 0 }; /* { dg-error "duplicate" } */ |
| 28 |
(void) (static register int) { 0 }; /* { dg-error "multiple storage classes in declaration specifiers" } */ |
| 29 |
(void) (register static int) { 0 }; /* { dg-error "multiple storage classes in declaration specifiers" } */ |
| 30 |
(void) (register thread_local int) { 0 }; /* { dg-error "used with" } */ |
| 31 |
(void) (thread_local register int) { 0 }; /* { dg-error "used with" } */ |
| 32 |
} |
| 33 |
|
| 34 |
void |
| 35 |
h () |
| 36 |
{ |
| 37 |
/* The following cases are not part of the C23 syntax, but are detected |
| 38 |
specially by the parser. */ |
| 39 |
(static int) 0; /* { dg-error "storage class specifier in cast" } */ |
| 40 |
sizeof (static int); /* { dg-error "storage class specifier in" } */ |
| 41 |
alignof (static int); /* { dg-error "storage class specifier in" } */ |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
bad_scspec () |
| 46 |
{ |
| 47 |
/* Storage class specifiers not permitted in compound literals result in a |
| 48 |
syntax error. */ |
| 49 |
(typedef int) { 0 }; /* { dg-error "expected" } */ |
| 50 |
(auto int) { 0 }; /* { dg-error "expected" } */ |
| 51 |
(extern int) { 0 }; /* { dg-error "expected" } */ |
| 52 |
} |