1/* Test for constant expressions: GNU extensions.  */
2/* Origin: Joseph Myers <joseph@codesourcery.com> */
3/* { dg-do compile } */
4/* { dg-options "-std=gnu89 -pedantic-errors" } */
5
6int n;
7
8void
9f (void)
10{
11  int i = 0;
12  int a[n]; /* { dg-error "ISO C90 forbids variable length array" } */
13  enum e1 {
14    /* Integer constant expressions may not contain statement
15       expressions (not a permitted operand).  */
16    E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant expression" } */
17    /* { dg-error "ISO C forbids braced-groups" "ISO" { target *-*-* } 16 } */
18    /* Real and imaginary parts act like other arithmetic
19       operators.  */
20    E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant expression" } */
21    E3 = __real__ 0,
22    E4 = __imag__ (1 ? 0 : i++), /* { dg-error "constant" } */
23    E5 = __imag__ 0,
24    /* __alignof__ always constant.  */
25    E6 = __alignof__ (int[n]), /* { dg-error "ISO C90 forbids variable length array" } */
26    E7 = __alignof__ (a),
27    /* __extension__ ignored for constant expression purposes.  */
28    E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant expression" } */
29    E9 = __extension__ 0,
30    /* Conditional expressions with omitted arguments act like the
31       standard type.  */
32    E10 = (1 ? : i++), /* { dg-error "constant expression" } */
33    /* { dg-error "ISO C forbids omitting" "ISO" { target *-*-* } 32 } */
34    E11 = (1 ? : 0) /* { dg-error "ISO C forbids omitting" } */
35  };
36  enum e2 {
37    /* Complex integer constants may be cast directly to integer
38       types, but not after further arithmetic on them.  */
39    F1 = (int) (_Complex int) 2i, /* { dg-error "constant expression" } */
40    /* { dg-error "complex" "complex" { target *-*-* } 39 } */
41    /* { dg-error "imaginary" "imaginary" { target *-*-* } 39 } */
42    F2 = (int) +2i, /* { dg-error "constant expression" } */
43    /* { dg-error "imaginary" "ISO" { target *-*-* } 42 } */
44    F3 = (int) (1 + 2i), /* { dg-error "constant expression" } */
45    /* { dg-error "imaginary" "ISO" { target *-*-* } 44 } */
46    F4 = (int) 2i /* { dg-error "imaginary" } */
47  };
48  static double dr = __real__ (1.0 + 2.0i);
49  /* { dg-error "imaginary" "ISO" { target *-*-* } 48 } */
50  static double di = __imag__ (1.0 + 2.0i);
51  /* { dg-error "imaginary" "ISO" { target *-*-* } 50 } */
52  /* Statement expressions allowed in unevaluated subexpressions in
53     initializers in gnu99 but not gnu89.  */
54  static int j = (1 ? 0 : ({ 0; })); /* { dg-error "constant expression" } */
55  /* { dg-error "braced" "ISO" { target *-*-* } 54 } */
56}
57