1*67e74705SXin Li // RUN: %clang_cc1 %s -ffreestanding -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic -fpascal-strings -std=c99
2*67e74705SXin Li
3*67e74705SXin Li #include <stdint.h>
4*67e74705SXin Li #include <limits.h>
5*67e74705SXin Li
a()6*67e74705SXin Li int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
7*67e74705SXin Li
8*67e74705SXin Li // rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
9*67e74705SXin Li int expr;
10*67e74705SXin Li char w[__builtin_constant_p(expr) ? expr : 1];
11*67e74705SXin Li
12*67e74705SXin Li char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
13*67e74705SXin Li
14*67e74705SXin Li int implicitConversion = 1.0;
15*67e74705SXin Li char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
16*67e74705SXin Li
17*67e74705SXin Li // __builtin_constant_p as the condition of ?: allows arbitrary foldable
18*67e74705SXin Li // constants to be transmogrified into i-c-e's.
19*67e74705SXin Li char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
20*67e74705SXin Li
21*67e74705SXin Li struct c {
22*67e74705SXin Li int a : (
23*67e74705SXin Li __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
24*67e74705SXin Li expr // expected-error {{expression is not an integer constant expression}}
25*67e74705SXin Li ) : -1);
26*67e74705SXin Li };
27*67e74705SXin Li
28*67e74705SXin Li
29*67e74705SXin Li
30*67e74705SXin Li
test1(int n,int * p)31*67e74705SXin Li void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
test2(int n,int * p)32*67e74705SXin Li void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
33*67e74705SXin Li
34*67e74705SXin Li
35*67e74705SXin Li
36*67e74705SXin Li char array[1024/(sizeof (long))];
37*67e74705SXin Li
38*67e74705SXin Li int x['\xBb' == (char) 187 ? 1: -1];
39*67e74705SXin Li
40*67e74705SXin Li // PR1992
func(int x)41*67e74705SXin Li void func(int x)
42*67e74705SXin Li {
43*67e74705SXin Li switch (x) {
44*67e74705SXin Li case sizeof("abc"): break;
45*67e74705SXin Li case sizeof("loooong"): func(4);
46*67e74705SXin Li case sizeof("\ploooong"): func(4);
47*67e74705SXin Li }
48*67e74705SXin Li }
49*67e74705SXin Li
50*67e74705SXin Li
51*67e74705SXin Li // rdar://4213768
52*67e74705SXin Li int expr;
53*67e74705SXin Li char y[__builtin_constant_p(expr) ? -1 : 1];
54*67e74705SXin Li char z[__builtin_constant_p(4) ? 1 : -1];
55*67e74705SXin Li
56*67e74705SXin Li // Comma tests
57*67e74705SXin Li int comma1[0?1,2:3];
58*67e74705SXin Li int comma2[1||(1,2)]; // expected-warning {{use of logical '||' with constant operand}} \
59*67e74705SXin Li // expected-note {{use '|' for a bitwise operation}}
60*67e74705SXin Li int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}}
61*67e74705SXin Li
62*67e74705SXin Li // Pointer + __builtin_constant_p
63*67e74705SXin Li char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
64*67e74705SXin Li
65*67e74705SXin Li int illegaldiv1a[1 || 1/0];
66*67e74705SXin Li int illegaldiv1b[1 && 1/0]; //expected-error{{variable length array declaration not allowed at file scope}}
67*67e74705SXin Li
68*67e74705SXin Li int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}}
69*67e74705SXin Li int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
70*67e74705SXin Li // PR9262
71*67e74705SXin Li int illegaldiv4[0 / (1 / 0)]; // expected-error {{variable length array declaration not allowed at file scope}}
72*67e74705SXin Li
73*67e74705SXin Li int chooseexpr[__builtin_choose_expr(1, 1, expr)];
74*67e74705SXin Li int realop[(__real__ 4) == 4 ? 1 : -1];
75*67e74705SXin Li int imagop[(__imag__ 4) == 0 ? 1 : -1];
76*67e74705SXin Li
77*67e74705SXin Li int *PR14729 = 0 ?: 1/0; // expected-error {{not a compile-time constant}} expected-warning 3{{}}
78