| 1 |
/* Test C23 storage class specifiers in compound literals. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
#include <stddef.h> |
| 6 |
|
| 7 |
extern void abort (void); |
| 8 |
extern void exit (int); |
| 9 |
|
| 10 |
/* static is OK (although redundant) at file scope. */ |
| 11 |
int *ps = &(static int) { 1 }; |
| 12 |
size_t ss = sizeof (static int) { 1 }; |
| 13 |
int *psa = (static int [3]) { 1, 2, 3 }; |
| 14 |
|
| 15 |
int |
| 16 |
main () |
| 17 |
{ |
| 18 |
if (ps[0] != 1) |
| 19 |
abort (); |
| 20 |
if (ss != sizeof (int)) |
| 21 |
abort (); |
| 22 |
if (psa[0] != 1 || psa[1] != 2 || psa[2] != 3) |
| 23 |
abort (); |
| 24 |
if ((register int) { 3 } != 3) |
| 25 |
abort (); |
| 26 |
/* A static compound literal, like a static variable, is initialized once, |
| 27 |
but an automatic compound literal is initialized every time it is reached |
| 28 |
in the order of execution. */ |
| 29 |
int i = 0; |
| 30 |
lab: |
| 31 |
int *p = &(static int) { 0 }; |
| 32 |
if (*p != i) |
| 33 |
abort (); |
| 34 |
i++; |
| 35 |
*p = i; |
| 36 |
if (i < 5) |
| 37 |
goto lab; |
| 38 |
i = 0; |
| 39 |
lab2: |
| 40 |
int *p2 = &(int) { 0 }; |
| 41 |
if (*p2 != 0) |
| 42 |
abort (); |
| 43 |
i++; |
| 44 |
*p2 = i; |
| 45 |
if (i < 5) |
| 46 |
goto lab2; |
| 47 |
exit (0); |
| 48 |
} |