1/* Test for constant expressions: cases involving VLAs, at file scope.  */
2/* Origin: Joseph Myers <joseph@codesourcery.com> */
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   <LV7g2Vy3ARF$Ew9Q@romana.davros.org>; 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
19static int sa[100];
20
21volatile int nv;
22int m;
23int n;
24int f (int, int);
25
26static int (*a2)[] = (int (*)[n])sa;
27static int (*a8)[] = (int (*)[(m=n)])sa; /* { dg-error "constant" } */
28static int (*a9)[] = (int (*)[(m+=n)])sa; /* { dg-error "constant" } */
29static int (*a10)[] = (int (*)[f(m,n)])sa; /* { dg-error "constant" } */
30static int (*a11)[] = (int (*)[(m,n)])sa; /* { dg-error "constant" } */
31static int (*a12)[] = (int (*)[sizeof(int[n])])sa;
32static int (*a13)[] = (int (*)[sizeof(int[m++])])sa; /* { dg-error "constant" } */
33static int (*a15)[] = (int (*)[sizeof(*(int (*)[n])sa)])sa;
34static int (*a16)[] = (int (*)[sizeof(*(int (*)[m++])sa)])sa; /* { dg-error "constant" } */
35static int (*a17)[] = (int (*)[nv])sa;
36