1 /* Test for constant expressions: GNU extensions. */
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu90 -pedantic-errors" } */
12 int a
[n
]; /* { dg-error "ISO C90 forbids variable length array" } */
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
20 E2
= __real__ (1 ? 0 : i
++), /* { dg-error "constant expression" } */
22 E4
= __imag__ (1 ? 0 : i
++), /* { dg-error "constant" } */
24 /* __alignof__ always constant. */
25 E6
= __alignof__ (int[n
]), /* { dg-error "ISO C90 forbids variable length array" } */
26 E7
= __alignof__ (a
), /* { dg-error "__alignof__ \\(expression\\)" } */
27 /* __extension__ ignored for constant expression purposes. */
28 E8
= __extension__ (1 ? 0 : i
++), /* { dg-error "constant expression" } */
30 /* Conditional expressions with omitted arguments act like the
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" } */
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" } */
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 } */