| 1 |
/* Test for constant expressions: operands and casts not permitted in |
| 2 |
integer constant expressions. */ |
| 3 |
/* Origin: Joseph Myers <[email protected]> */ |
| 4 |
/* { dg-do compile } */ |
| 5 |
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ |
| 6 |
|
| 7 |
/* PR 29116. */ |
| 8 |
int n = 0, p[n * 0 + 1]; /* { dg-error "variabl" } */ |
| 9 |
|
| 10 |
/* PR 31871. */ |
| 11 |
extern int c[1 + ((__INTPTR_TYPE__) (void *) 0)]; /* { dg-error "variab" } */ |
| 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" } */ |
| 16 |
|
| 17 |
extern int c2[(int)1.0 ? 1 : 0]; |
| 18 |
|
| 19 |
extern int c3[1.0 && 1]; /* { dg-error "variab" } */ |
| 20 |
|
| 21 |
extern int c4[(int)1.0 && 1]; |
| 22 |
|
| 23 |
extern int c5[1.0 || 1]; /* { dg-error "variab" } */ |
| 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 + ((__INTPTR_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 |
/* Presume that a compound literal, being a reference to an anonymous |
| 45 |
variable, is not allowed in an integer constant expression |
| 46 |
regardless of what initializers it contains. */ |
| 47 |
enum g { |
| 48 |
G = (1 ? 1 : (int){0}), /* { dg-error "constant" } */ |
| 49 |
G2 = 0 |
| 50 |
}; |
| 51 |
|
| 52 |
int v[2] = { [(n * 0 + 1)] = 1 }; /* { dg-error "constant|near initialization" } */ |
| 53 |
|
| 54 |
void |
| 55 |
f (int a) |
| 56 |
{ |
| 57 |
switch (a) |
| 58 |
{ |
| 59 |
case (n * 0 + 1): /* { dg-error "constant" } */ |
| 60 |
; |
| 61 |
} |
| 62 |
} |