2018-05-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / c90-const-expr-6.c
blob50239ce2eba246be27c6bcca948712242ba6e3a1
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" } */
7 __extension__ typedef __INTPTR_TYPE__ intptr_t;
9 /* PR 29116. */
10 int n = 0, p[n * 0 + 1]; /* { dg-error "variabl|can't be evaluated" } */
12 /* PR 31871. */
13 extern int c[1 + ((intptr_t) (void *) 0)]; /* { dg-error "variab|can't be evaluated" } */
15 /* Implicit conversions from floating-point constants are not OK,
16 although explicit ones are. */
17 extern int c1[1.0 ? 1 : 0]; /* { dg-error "variab|can't be evaluated" } */
19 extern int c2[(int)1.0 ? 1 : 0];
21 extern int c3[1.0 && 1]; /* { dg-error "variab|can't be evaluated" } */
23 extern int c4[(int)1.0 && 1];
25 extern int c5[1.0 || 1]; /* { dg-error "variab|can't be evaluated" } */
27 extern int c6[(int)1.0 || 1];
29 /* Similar with various other cases where integer constant expressions
30 are required. */
32 struct s {
33 int a : (n * 0 + 1); /* { dg-error "constant" } */
36 enum e {
37 E = (1 + ((intptr_t) (void *) 0)), /* { dg-error "constant" } */
38 E2 = 0
41 enum f {
42 F = (1 ? 1 : n), /* { dg-error "constant" } */
43 F2 = 0
46 void
47 f (int a)
49 int v[1 + ((intptr_t) (void *) 0)]; /* { dg-error "variab|can't be evaluated" } */
50 switch (a)
52 case (n * 0 + 1): /* { dg-error "constant" } */