[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Sema / i-c-e.c
blob4da6c93ac86d39de923cf8ba52d7d682033c5586
1 // RUN: %clang_cc1 %s -ffreestanding -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic -fpascal-strings -std=c99
3 #include <stdint.h>
4 #include <limits.h>
6 int a(void) {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
8 // rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
9 int expr;
10 char w[__builtin_constant_p(expr) ? expr : 1];
12 char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
14 int implicitConversion = 1.0;
15 char floatArith[(int)(1.0+2.0)]; // expected-warning {{variable length array folded to constant array as an extension}}
17 // __builtin_constant_p as the condition of ?: allows arbitrary foldable
18 // constants to be transmogrified into i-c-e's.
19 char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
21 struct c {
22 int a : (
23 __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
24 expr // expected-error {{expression is not an integer constant expression}}
25 ) : -1);
28 // Check that we can evaluate statement-expressions properly when
29 // constant-folding inside an ICE.
30 void PR49239(void) {
31 goto check_not_vla;
32 char not_vla[__builtin_constant_p(1) ? ({ 42; }) : -1]; // expected-warning {{statement expression}}
33 check_not_vla:;
34 _Static_assert(sizeof(not_vla) == 42, ""); // expected-warning {{C11 extension}}
36 // It's not clear that this should be valid: __builtin_expect(expr1, expr2)
37 // should probably be an ICE if and only if expr1 is an ICE, but we roughly
38 // follow GCC in treating it as an ICE if and only if we can evaluate expr1
39 // regardless of whether it's an ICE.
40 goto check_also_not_vla;
41 char also_not_vla[__builtin_expect(({ 76; }), 0)]; // expected-warning {{statement expression}}
42 check_also_not_vla:;
43 _Static_assert(sizeof(also_not_vla) == 76, ""); // expected-warning {{C11 extension}}
47 void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
48 void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
52 char array[1024/(sizeof (long))];
54 int x['\xBb' == (char) 187 ? 1: -1];
56 // PR1992
57 void func(int x)
59 switch (x) {
60 case sizeof("abc"): break;
61 case sizeof("loooong"): func(4);
62 case sizeof("\ploooong"): func(4);
67 // rdar://4213768
68 int expr;
69 char y[__builtin_constant_p(expr) ? -1 : 1];
70 char z[__builtin_constant_p(4) ? 1 : -1];
72 // Comma tests
73 int comma1[0?1,2:3]; // expected-warning {{left operand of comma operator has no effect}}
74 int comma2[1 || (1, 2)]; // expected-warning {{use of logical '||' with constant operand}} \
75 // expected-note {{use '|' for a bitwise operation}} \
76 // expected-warning {{left operand of comma operator has no effect}}
77 int comma3[(1, 2)]; // expected-warning {{variable length array folded to constant array as an extension}} \
78 // expected-warning {{left operand of comma operator has no effect}}
80 // Pointer + __builtin_constant_p
81 char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
83 int illegaldiv1a[1 || 1/0];
84 int illegaldiv1b[1 && 1/0]; //expected-error{{variable length array declaration not allowed at file scope}}
86 int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}}
87 int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
88 // PR9262
89 int illegaldiv4[0 / (1 / 0)]; // expected-error {{variable length array declaration not allowed at file scope}}
91 int chooseexpr[__builtin_choose_expr(1, 1, expr)];
92 int realop[(__real__ 4) == 4 ? 1 : -1];
93 int imagop[(__imag__ 4) == 0 ? 1 : -1];
95 int *PR14729 = 0 ?: 1/0; // expected-error {{not a compile-time constant}} expected-warning 3{{}}
97 int bcp_call_v;
98 int bcp_call_a[] = {__builtin_constant_p(bcp_call_v && 0) ? bcp_call_v && 0 : -1};