1 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
4 _Complex
double test1() {
5 return __extension__
1.0if;
8 _Complex
double test2() {
9 return 1.0if; // expected-warning {{imaginary constants are an extension}}
15 (__extension__ x
) = 10;
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 +.
26 var
=+5; // no warning when the subexpr of the unary op has no space before it.
30 var
=-FIVE
; // no warning with macros.
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}}
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')}}
54 __builtin_choose_expr (0, 42, i
) = 10;
60 struct f
{ int x
: 4; float y
[]; };
61 int test9(struct f
*P
) {
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}}
70 void test10(int n
,...) {
72 double a
[n
]; // expected-error {{fields must have a constant size}}
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'))}}
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
96 void (^P
)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
98 P
= ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
102 typedef long long __m64
__attribute__((__vector_size__(8)));
103 typedef short __v4hi
__attribute__((__vector_size__(8)));
107 __m64 mask
= (__m64
)((__v4hi
)a
> (__v4hi
)a
);
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')}}
119 void test16(float x
) { x
== ((void*) 0); } // expected-error {{invalid operands to binary expression}}
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.
132 void test18_a(int a
);
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}}
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.
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.