2018-01-10 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / gnu99-const-expr-1.c
blob4148cd9f0792e326b851b04a6dc0b03937c7d2fb
1 /* Test for constant expressions: GNU extensions. */
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu99 -pedantic-errors" } */
6 int n;
8 void
9 f (void)
11 int i = 0;
12 int a[n];
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 *-*-* } .-1 } */
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]),
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 *-*-* } .-1 } */
34 E11 = (1 ? : 0) /* { dg-error "ISO C forbids omitting" } */
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 *-*-* } .-1 } */
41 /* { dg-error "imaginary" "imaginary" { target *-*-* } .-2 } */
42 F2 = (int) +2i, /* { dg-error "constant expression" } */
43 /* { dg-error "imaginary" "ISO" { target *-*-* } .-1 } */
44 F3 = (int) (1 + 2i), /* { dg-error "constant expression" } */
45 /* { dg-error "imaginary" "ISO" { target *-*-* } .-1 } */
46 F4 = (int) 2i /* { dg-error "imaginary" } */
48 static double dr = __real__ (1.0 + 2.0i);
49 /* { dg-error "imaginary" "ISO" { target *-*-* } .-1 } */
50 static double di = __imag__ (1.0 + 2.0i);
51 /* { dg-error "imaginary" "ISO" { target *-*-* } .-1 } */
52 /* Statement expressions allowed in unevaluated subexpressions in
53 initializers in gnu99 but not gnu89. */
54 static int j = (1 ? 0 : ({ 0; }));
55 /* { dg-error "braced" "ISO" { target *-*-* } .-1 } */