blob: 617eaa086cf433861a300520a7c457814938c703 [file] [log] [blame]
Daniel Dunbar9d805ce2009-04-07 21:16:11 +00001// RUN: clang-cc %s -verify -pedantic -fsyntax-only -fblocks=0
Chris Lattner6cf92942008-02-02 20:20:10 +00002
3// PR1966
4_Complex double test1() {
5 return __extension__ 1.0if;
6}
7
8_Complex double test2() {
9 return 1.0if; // expected-warning {{imaginary constants are an extension}}
10}
11
Chris Lattner1b843a22008-07-25 18:07:19 +000012// rdar://6097308
13void test3() {
14 int x;
15 (__extension__ x) = 10;
16}
17
Chris Lattner34c85082008-08-21 18:04:13 +000018// rdar://6162726
19void 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 (-=)}}
Chris Lattner55a17242009-03-08 06:51:10 +000023 var = +5; // no warning when space between the = and +.
Chris Lattner34c85082008-08-21 18:04:13 +000024 var = -5;
Chris Lattner55a17242009-03-08 06:51:10 +000025
26 var =+5; // no warning when the subexpr of the unary op has no space before it.
27 var =-5;
Chris Lattnerf1e5d4a2009-03-09 07:11:10 +000028
29#define FIVE 5
30 var=-FIVE; // no warning with macros.
31 var=-FIVE;
Chris Lattner34c85082008-08-21 18:04:13 +000032}
33
Chris Lattner37fb9402008-11-17 19:51:54 +000034// rdar://6319320
35void test5(int *X, float *P) {
36 (float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
Daniel Dunbar930e1242009-04-14 23:26:44 +000037 ((float*)X) = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
Chris Lattner37fb9402008-11-17 19:51:54 +000038}
39
Chris Lattner036094b2008-11-21 18:27:34 +000040void test6() {
41 int X;
42 X(); // expected-error {{called object type 'int' is not a function or function pointer}}
43}
Chris Lattner3aabf952008-11-22 19:57:03 +000044
45void test7(int *P, _Complex float Gamma) {
46 P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
47}
48
Chris Lattnera5f779dc2008-12-12 05:35:08 +000049
50// rdar://6095061
51int test8(void) {
52 int i;
Chris Lattner9b937e52008-12-12 05:59:56 +000053 __builtin_choose_expr (0, 42, i) = 10; // expected-warning {{extension used}}
Chris Lattnera5f779dc2008-12-12 05:35:08 +000054 return i;
55}
Chris Lattner8d9f7962009-01-24 20:17:12 +000056
57
58// PR3386
59struct f { int x : 4; float y[]; };
60int test9(struct f *P) {
Chris Lattner364a42d2009-01-24 21:29:22 +000061 int R;
62 R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
63 R = __alignof(P->y); // ok. expected-warning {{extension used}}
64 R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
65 return R;
Chris Lattner8d9f7962009-01-24 20:17:12 +000066}
67
Chris Lattnerfd57ecc2009-02-13 22:08:30 +000068// PR3562
69void test10(int n,...) {
70 struct S {
71 double a[n]; // expected-error {{fields must have a constant size}}
72 } s;
73 double x = s.a[0]; // should not get another error here.
74}
Chris Lattner2bd4a5a2009-02-19 23:45:49 +000075
76
77#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
78
79struct mystruct {int A; };
Chris Lattner4e479f92009-03-08 19:39:53 +000080void test11(struct mystruct P, float F) {
Chris Lattner2bd4a5a2009-02-19 23:45:49 +000081 MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))}}
82}
83
Chris Lattner4e479f92009-03-08 19:39:53 +000084// PR3753
85int test12(const char *X) {
Chris Lattner6b6513d2009-03-08 19:52:14 +000086 return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
Chris Lattner4e479f92009-03-08 19:39:53 +000087}
88
Chris Lattnerc14c7f02009-03-27 04:18:06 +000089// rdar://6719156
90void test13(
91 void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
92 P();
93 P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
94}
Chris Lattner10687e32009-03-31 07:46:52 +000095
96
97// rdar://6326239 - Vector comparisons are not fully trusted yet, until the
98// backend is known to work, just unconditionally reject them.
99void test14() {
100 typedef long long __m64 __attribute__((__vector_size__(8))); // expected-warning {{extension used}}
101 typedef short __v4hi __attribute__((__vector_size__(8))); // expected-warning {{extension used}}
102
103 __v4hi a;
104 __m64 mask = (__m64)((__v4hi)a > // expected-error {{comparison of vector types ('__v4hi' and '__v4hi') not supported yet}}
105 (__v4hi)a);
106}
107