| 1 |
/* Test for constant expressions: cases involving VLAs, at file scope. */ |
| 2 |
/* Origin: Joseph Myers <[email protected]> */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ |
| 5 |
|
| 6 |
/* It appears address constants may contain casts to variably modified |
| 7 |
types. Whether they should be permitted was discussed in |
| 8 |
<http://groups.google.com/group/comp.std.c/msg/923eee5ab690fd98> |
| 9 |
<[email protected]>; since static pointers to VLAs |
| 10 |
are definitely permitted within functions and may be initialized |
| 11 |
and such initialization involves implicit conversion to a variably |
| 12 |
modified type, allowing explicit casts seems appropriate. Thus, |
| 13 |
GCC allows them as long as the "evaluated" size expressions do not |
| 14 |
contain the various operators not permitted to be evaluated in a |
| 15 |
constant expression, and as long as the result is genuinely |
| 16 |
constant (meaning that pointer arithmetic using the size of the VLA |
| 17 |
is generally not permitted). */ |
| 18 |
|
| 19 |
static int sa[100]; |
| 20 |
|
| 21 |
volatile int nv; |
| 22 |
int m; |
| 23 |
int n; |
| 24 |
int f (int, int); |
| 25 |
|
| 26 |
static int (*a2)[] = (int (*)[n])sa; |
| 27 |
static int (*a8)[] = (int (*)[(m=n)])sa; /* { dg-error "constant" } */ |
| 28 |
static int (*a9)[] = (int (*)[(m+=n)])sa; /* { dg-error "constant" } */ |
| 29 |
static int (*a10)[] = (int (*)[f(m,n)])sa; /* { dg-error "constant" } */ |
| 30 |
static int (*a11)[] = (int (*)[(m,n)])sa; /* { dg-error "constant" } */ |
| 31 |
static int (*a12)[] = (int (*)[sizeof(int[n])])sa; |
| 32 |
static int (*a13)[] = (int (*)[sizeof(int[m++])])sa; /* { dg-error "constant" } */ |
| 33 |
static int (*a15)[] = (int (*)[sizeof(*(int (*)[n])sa)])sa; |
| 34 |
static int (*a16)[] = (int (*)[sizeof(*(int (*)[m++])sa)])sa; /* { dg-error "constant" } */ |
| 35 |
static int (*a17)[] = (int (*)[nv])sa; |