Allow resolving headers from a PCH even after headers+PCH were moved to another path.
[clang.git] / test / Sema / exprs.c
blobe88f7fc08bce2621e6b7ee3c3496d4b3ea505c8c
1 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
3 // PR1966
4 _Complex double test1() {
5 return __extension__ 1.0if;
8 _Complex double test2() {
9 return 1.0if; // expected-warning {{imaginary constants are an extension}}
12 // rdar://6097308
13 void test3() {
14 int x;
15 (__extension__ x) = 10;
18 // rdar://6162726
19 void test4() {
20 static int var;
21 var =+ 5; // expected-warning {{use of unary operator that may be intended as compound assignment (+=)}}
22 var =- 5; // expected-warning {{use of unary operator that may be intended as compound assignment (-=)}}
23 var = +5; // no warning when space between the = and +.
24 var = -5;
26 var =+5; // no warning when the subexpr of the unary op has no space before it.
27 var =-5;
29 #define FIVE 5
30 var=-FIVE; // no warning with macros.
31 var=-FIVE;
34 // rdar://6319320
35 void test5(int *X, float *P) {
36 (float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
37 #define FOO ((float*) X)
38 FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
41 void test6() {
42 int X;
43 X(); // expected-error {{called object type 'int' is not a function or function pointer}}
46 void test7(int *P, _Complex float Gamma) {
47 P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
51 // rdar://6095061
52 int test8(void) {
53 int i;
54 __builtin_choose_expr (0, 42, i) = 10;
55 return i;
59 // PR3386
60 struct f { int x : 4; float y[]; };
61 int test9(struct f *P) {
62 int R;
63 R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}}
64 R = __alignof(P->y); // ok.
65 R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}}
66 return R;
69 // PR3562
70 void test10(int n,...) {
71 struct S {
72 double a[n]; // expected-error {{fields must have a constant size}}
73 } s;
74 double x = s.a[0]; // should not get another error here.
78 #define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
80 struct mystruct {int A; };
81 void test11(struct mystruct P, float F) {
82 MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof (P)' (aka 'struct mystruct') and 'typeof (F)' (aka 'float'))}}
85 // PR3753
86 int test12(const char *X) {
87 return X == "foo"; // expected-warning {{comparison against a string literal is unspecified (use strncmp instead)}}
90 int test12b(const char *X) {
91 return sizeof(X == "foo"); // no-warning
94 // rdar://6719156
95 void test13(
96 void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
97 P();
98 P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
101 void test14() {
102 typedef long long __m64 __attribute__((__vector_size__(8)));
103 typedef short __v4hi __attribute__((__vector_size__(8)));
105 // Ok.
106 __v4hi a;
107 __m64 mask = (__m64)((__v4hi)a > (__v4hi)a);
111 // PR5242
112 typedef unsigned long *test15_t;
114 test15_t test15(void) {
115 return (test15_t)0 + (test15_t)0; // expected-error {{invalid operands to binary expression ('test15_t' (aka 'unsigned long *') and 'test15_t')}}
118 // rdar://7446395
119 void test16(float x) { x == ((void*) 0); } // expected-error {{invalid operands to binary expression}}
121 // PR6004
122 void test17(int x) {
123 x = x / 0; // expected-warning {{division by zero is undefined}}
124 x = x % 0; // expected-warning {{remainder by zero is undefined}}
125 x /= 0; // expected-warning {{division by zero is undefined}}
126 x %= 0; // expected-warning {{remainder by zero is undefined}}
128 x = sizeof(x/0); // no warning.
131 // PR6501
132 void test18_a(int a);
133 void test18(int b) {
134 test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}}
135 test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}}
138 // PR7569
139 void test19() {
140 *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \
141 // expected-note {{consider using __builtin_trap}}
142 *(volatile int*)0 = 0; // Ok.
145 int test20(int x) {
146 return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
148 return x && sizeof(int) == 4; // no warning, RHS is logical op.
150 // no warning, this is an idiom for "true" in old C style.
151 return x && (signed char)1;
154 struct Test21; // expected-note 2 {{forward declaration}}
155 void test21(volatile struct Test21 *ptr) {
156 void test21_help(void);
157 (test21_help(), *ptr); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
158 (*ptr, test21_help()); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
161 // Make sure we do function/array decay.
162 void test22() {
163 if ("help")
164 (void) 0;
166 if (test22)
167 (void) 0;