blob: eb77bbe3b99023b32052bd861aa454ccc9e9ffa0 [file] [log] [blame]
Daniel Dunbar80737ad2009-12-15 22:01:24 +00001// RUN: %clang %s -fsyntax-only -Xclang -verify -pedantic -fpascal-strings
Chris Lattner04de9932008-12-12 07:01:24 +00002
Eli Friedmanf04ec672009-02-27 04:46:32 +00003#include <stdint.h>
4#include <limits.h>
5
Eli Friedman09de1762009-04-25 22:37:12 +00006int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
Chris Lattner04de9932008-12-12 07:01:24 +00007
8// rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
9int expr;
10char w[__builtin_constant_p(expr) ? expr : 1];
11
12
Chris Lattner42b83dd2008-12-12 18:00:51 +000013// __builtin_constant_p as the condition of ?: allows arbitrary foldable
14// constants to be transmogrified into i-c-e's.
15char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
16
17struct c {
18 int a : ( // expected-error {{expression is not an integer constant expression}}
19 __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
20 expr // expected-note {{subexpression not valid in an integer constant expression}}
21 ) : -1);
22};
23
24
25
Chris Lattner04de9932008-12-12 07:01:24 +000026
27void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
28void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
29
30
31
32char array[1024/(sizeof (long))];
33
34int x['\xBb' == (char) 187 ? 1: -1];
35
36// PR1992
37void func(int x)
38{
39 switch (x) {
40 case sizeof("abc"): break;
41 case sizeof("loooong"): func(4);
42 case sizeof("\ploooong"): func(4);
43 }
44}
45
46
47// rdar://4213768
48int expr;
49char y[__builtin_constant_p(expr) ? -1 : 1];
50char z[__builtin_constant_p(4) ? 1 : -1];
51
Eli Friedmanf04ec672009-02-27 04:46:32 +000052// Comma tests
Argyrios Kyrtzidis1b2ad2f2010-09-19 23:03:35 +000053int comma1[0?1,2:3]; // expected-warning {{expression result unused}}
54int comma2[1||(1,2)]; // expected-warning {{expression result unused}} \
55 // expected-warning {{use of logical || with constant operand}}
56int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}} \
57 // expected-warning {{expression result unused}}
Eli Friedmanf04ec672009-02-27 04:46:32 +000058
59// Pointer + __builtin_constant_p
60char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
61
Chris Lattner7ef655a2010-01-12 21:23:57 +000062int illegaldiv1[1 || 1/0]; // expected-warning {{division by zero is undefined}}
63int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \
64 // expected-warning {{division by zero is undefined}}
Eli Friedmanf04ec672009-02-27 04:46:32 +000065int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
66
Eli Friedmaneb32fde2009-04-28 03:13:54 +000067int chooseexpr[__builtin_choose_expr(1, 1, expr)];
68int realop[(__real__ 4) == 4 ? 1 : -1];
69int imagop[(__imag__ 4) == 0 ? 1 : -1];