blob: e6cfa5fbe3e4f22ea079e61eb4bd77a33ebd5060 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
Chris Lattner35080842008-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 Lattnerbaf0d662008-07-25 18:07:19 +000012// rdar://6097308
13void test3() {
14 int x;
15 (__extension__ x) = 10;
16}
17
Chris Lattner2c156472008-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 Lattner399bd1b2009-03-08 06:51:10 +000023 var = +5; // no warning when space between the = and +.
Chris Lattner2c156472008-08-21 18:04:13 +000024 var = -5;
Chris Lattner399bd1b2009-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 Lattner3e872092009-03-09 07:11:10 +000028
29#define FIVE 5
30 var=-FIVE; // no warning with macros.
31 var=-FIVE;
Chris Lattner2c156472008-08-21 18:04:13 +000032}
33
Chris Lattnerca354fa2008-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 Dunbar44e35f72009-04-15 00:08:05 +000037#define FOO ((float*) X)
38 FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
Chris Lattnerca354fa2008-11-17 19:51:54 +000039}
40
Chris Lattnerb1b4d332008-11-21 18:27:34 +000041void test6() {
42 int X;
43 X(); // expected-error {{called object type 'int' is not a function or function pointer}}
44}
Chris Lattner7ca14252008-11-22 19:57:03 +000045
46void test7(int *P, _Complex float Gamma) {
47 P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
48}
49
Chris Lattner670a62c2008-12-12 05:35:08 +000050
51// rdar://6095061
52int test8(void) {
53 int i;
Eli Friedmaneb32fde2009-04-28 03:13:54 +000054 __builtin_choose_expr (0, 42, i) = 10;
Chris Lattner670a62c2008-12-12 05:35:08 +000055 return i;
56}
Chris Lattner31e21e02009-01-24 20:17:12 +000057
58
59// PR3386
60struct f { int x : 4; float y[]; };
61int test9(struct f *P) {
Chris Lattnerda027472009-01-24 21:29:22 +000062 int R;
Anders Carlsson31fddcc2009-09-14 22:00:20 +000063 R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}}
Eli Friedmaneb32fde2009-04-28 03:13:54 +000064 R = __alignof(P->y); // ok.
Anders Carlsson31fddcc2009-09-14 22:00:20 +000065 R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}}
Chris Lattnerda027472009-01-24 21:29:22 +000066 return R;
Chris Lattner31e21e02009-01-24 20:17:12 +000067}
68
Chris Lattner56cd21b2009-02-13 22:08:30 +000069// PR3562
70void 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.
75}
Chris Lattnerd0344a42009-02-19 23:45:49 +000076
77
78#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
79
80struct mystruct {int A; };
Chris Lattner55660a72009-03-08 19:39:53 +000081void test11(struct mystruct P, float F) {
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +000082 MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof (P)' (aka 'struct mystruct') and 'typeof (F)' (aka 'float'))}}
Chris Lattnerd0344a42009-02-19 23:45:49 +000083}
84
Chris Lattner55660a72009-03-08 19:39:53 +000085// PR3753
86int test12(const char *X) {
Chris Lattner466a7f82009-03-08 19:52:14 +000087 return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
Chris Lattner55660a72009-03-08 19:39:53 +000088}
89
Chris Lattner9af55002009-03-27 04:18:06 +000090// rdar://6719156
91void test13(
92 void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
93 P();
94 P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
95}
Chris Lattnerd013aa12009-03-31 07:46:52 +000096
Chris Lattnerd013aa12009-03-31 07:46:52 +000097void test14() {
Eli Friedmaneb32fde2009-04-28 03:13:54 +000098 typedef long long __m64 __attribute__((__vector_size__(8)));
99 typedef short __v4hi __attribute__((__vector_size__(8)));
Chris Lattnerd013aa12009-03-31 07:46:52 +0000100
Chris Lattner9c10fcf2009-07-08 01:08:03 +0000101 // Ok.
Chris Lattnerd013aa12009-03-31 07:46:52 +0000102 __v4hi a;
Chris Lattner9c10fcf2009-07-08 01:08:03 +0000103 __m64 mask = (__m64)((__v4hi)a > (__v4hi)a);
Chris Lattnerd013aa12009-03-31 07:46:52 +0000104}
105
Chris Lattner0a026af2009-10-20 05:36:05 +0000106
107// PR5242
108typedef unsigned long *test15_t;
109
110test15_t test15(void) {
111 return (test15_t)0 + (test15_t)0; // expected-error {{invalid operands to binary expression ('test15_t' (aka 'unsigned long *') and 'test15_t')}}
112}
113
Chris Lattner02dd4b12009-12-05 05:40:13 +0000114// rdar://7446395
115void test16(float x) { x == ((void*) 0); } // expected-error {{invalid operands to binary expression}}
Chris Lattner0a026af2009-10-20 05:36:05 +0000116