OSDN Git Service

PR c/456
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / gnu99-const-expr-1.c
1 /* Test for constant expressions: GNU extensions.  */
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu99" } */
5
6 int n;
7
8 void
9 f (void)
10 {
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" } */
17     /* Real and imaginary parts act like other arithmetic
18        operators.  */
19     E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant" } */
20     E3 = __real__ 0,
21     E4 = __imag__ (1 ? 0 : i++), /* { dg-error "constant" } */
22     E5 = __imag__ 0,
23     /* __alignof__ always constant.  */
24     E6 = __alignof__ (int[n]),
25     E7 = __alignof__ (a),
26     /* __extension__ ignored for constant expression purposes.  */
27     E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant" } */
28     E9 = __extension__ 0,
29     /* Conditional expressions with omitted arguments act like the
30        standard type.  */ 
31     E10 = (1 ? : i++), /* { dg-error "constant" } */
32     E11 = (1 ? : 0)
33   };
34   enum e2 {
35     /* Complex integer constants may be cast directly to integer
36        types, but not after further arithmetic on them.  */
37     F1 = (int) (_Complex int) 2i, /* { dg-error "constant" } */
38     F2 = (int) +2i, /* { dg-error "constant" } */
39     F3 = (int) (1 + 2i), /* { dg-error "constant" } */
40     F4 = (int) 2i
41   };
42   static double dr = __real__ (1.0 + 2.0i);
43   static double di = __imag__ (1.0 + 2.0i);
44   /* Statement expressions allowed in unevaluated subexpressions in
45      initializers in gnu99 but not gnu89.  */
46   static int j = (1 ? 0 : ({ 0; }));
47 }