1/* Test for constant expressions: cases involving VLAs and typeof, at 2 file scope. */ 3/* Origin: Joseph Myers <joseph@codesourcery.com> */ 4/* { dg-do compile } */ 5/* { dg-options "-std=gnu99 -pedantic-errors" } */ 6 7/* It appears address constants may contain casts to variably modified 8 types. Whether they should be permitted was discussed in 9 <http://groups.google.com/group/comp.std.c/msg/923eee5ab690fd98> 10 <LV7g2Vy3ARF$Ew9Q@romana.davros.org>; since static pointers to VLAs 11 are definitely permitted within functions and may be initialized 12 and such initialization involves implicit conversion to a variably 13 modified type, allowing explicit casts seems appropriate. Thus, 14 GCC allows them as long as the "evaluated" size expressions do not 15 contain the various operators not permitted to be evaluated in a 16 constant expression, and as long as the result is genuinely 17 constant (meaning that pointer arithmetic using the size of the VLA 18 is generally not permitted). */ 19 20static int sa[100]; 21int m; 22int n; 23 24static int (*a1)[] = &sa; 25static int (*a2)[] = (__typeof__(int (*)[n]))sa; 26static int (*a4)[] = (__typeof__((int (*)[n])sa))sa; 27static int (*a5)[] = (__typeof__((int (*)[m++])sa))sa; /* { dg-error "constant" } */ 28static int (*a6)[] = (__typeof__((int (*)[100])(int (*)[m++])sa))sa; 29static int (*a7)[] = (__typeof__((int (*)[n])sa + m++))sa; /* { dg-error "constant" } */ 30