OSDN Git Service

PR c/456
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / c90-const-expr-6.c
1 /* Test for constant expressions: operands and casts not permitted in
2    integer constant expressions.  */
3 /* Origin: Joseph Myers <joseph@codesourcery.com> */
4 /* { dg-do compile } */
5 /* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
6
7 /* PR 29116.  */
8 int n = 0, p[n * 0 + 1]; /* { dg-error "variabl|can't be evaluated" } */
9
10 /* PR 31871.  */
11 extern int c[1 + ((__PTRDIFF_TYPE__) (void *) 0)]; /* { dg-error "variab|can't be evaluated" } */
12
13 /* Implicit conversions from floating-point constants are not OK,
14    although explicit ones are.  */
15 extern int c1[1.0 ? 1 : 0]; /* { dg-error "variab|can't be evaluated" } */
16
17 extern int c2[(int)1.0 ? 1 : 0];
18
19 extern int c3[1.0 && 1]; /* { dg-error "variab|can't be evaluated" } */
20
21 extern int c4[(int)1.0 && 1];
22
23 extern int c5[1.0 || 1]; /* { dg-error "variab|can't be evaluated" } */
24
25 extern int c6[(int)1.0 || 1];
26
27 /* Similar with various other cases where integer constant expressions
28    are required.  */
29
30 struct s {
31   int a : (n * 0 + 1); /* { dg-error "constant" } */
32 };
33
34 enum e {
35   E = (1 + ((__PTRDIFF_TYPE__) (void *) 0)), /* { dg-error "constant" } */
36   E2 = 0
37 };
38
39 enum f {
40   F = (1 ? 1 : n), /* { dg-error "constant" } */
41   F2 = 0
42 };
43
44 void
45 f (int a)
46 {
47   int v[1 + ((__PTRDIFF_TYPE__) (void *) 0)]; /* { dg-error "variab|can't be evaluated" } */
48   switch (a)
49     {
50     case (n * 0 + 1): /* { dg-error "constant" } */
51       ;
52     }
53 }