Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 1 | // RUN: clang %s -fsyntax-only -verify -pedantic -fpascal-strings |
| 2 | |
| 3 | int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} |
| 4 | |
| 5 | // rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e. |
| 6 | int expr; |
| 7 | char w[__builtin_constant_p(expr) ? expr : 1]; |
| 8 | |
| 9 | |
Chris Lattner | 42b83dd | 2008-12-12 18:00:51 +0000 | [diff] [blame] | 10 | // __builtin_constant_p as the condition of ?: allows arbitrary foldable |
| 11 | // constants to be transmogrified into i-c-e's. |
| 12 | char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1]; |
| 13 | |
| 14 | struct c { |
| 15 | int a : ( // expected-error {{expression is not an integer constant expression}} |
| 16 | __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+ |
| 17 | expr // expected-note {{subexpression not valid in an integer constant expression}} |
| 18 | ) : -1); |
| 19 | }; |
| 20 | |
| 21 | |
| 22 | |
Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 23 | |
| 24 | void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; } |
| 25 | void test2(int n, int* p) { *(n ? p : (void *)0) = 1; } |
| 26 | |
| 27 | |
| 28 | |
| 29 | char array[1024/(sizeof (long))]; |
| 30 | |
| 31 | int x['\xBb' == (char) 187 ? 1: -1]; |
| 32 | |
| 33 | // PR1992 |
| 34 | void func(int x) |
| 35 | { |
| 36 | switch (x) { |
| 37 | case sizeof("abc"): break; |
| 38 | case sizeof("loooong"): func(4); |
| 39 | case sizeof("\ploooong"): func(4); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
| 44 | // rdar://4213768 |
| 45 | int expr; |
| 46 | char y[__builtin_constant_p(expr) ? -1 : 1]; |
| 47 | char z[__builtin_constant_p(4) ? 1 : -1]; |
| 48 | |