Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only |
Chris Lattner | 3508084 | 2008-02-02 20:20:10 +0000 | [diff] [blame] | 2 | |
| 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 Lattner | baf0d66 | 2008-07-25 18:07:19 +0000 | [diff] [blame] | 12 | // rdar://6097308 |
| 13 | void test3() { |
| 14 | int x; |
| 15 | (__extension__ x) = 10; |
| 16 | } |
| 17 | |
Chris Lattner | 2c15647 | 2008-08-21 18:04:13 +0000 | [diff] [blame] | 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 (-=)}} |
Chris Lattner | 399bd1b | 2009-03-08 06:51:10 +0000 | [diff] [blame] | 23 | var = +5; // no warning when space between the = and +. |
Chris Lattner | 2c15647 | 2008-08-21 18:04:13 +0000 | [diff] [blame] | 24 | var = -5; |
Chris Lattner | 399bd1b | 2009-03-08 06:51:10 +0000 | [diff] [blame] | 25 | |
| 26 | var =+5; // no warning when the subexpr of the unary op has no space before it. |
| 27 | var =-5; |
Chris Lattner | 3e87209 | 2009-03-09 07:11:10 +0000 | [diff] [blame] | 28 | |
| 29 | #define FIVE 5 |
| 30 | var=-FIVE; // no warning with macros. |
| 31 | var=-FIVE; |
Chris Lattner | 2c15647 | 2008-08-21 18:04:13 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | ca354fa | 2008-11-17 19:51:54 +0000 | [diff] [blame] | 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}} |
Daniel Dunbar | 44e35f7 | 2009-04-15 00:08:05 +0000 | [diff] [blame] | 37 | #define FOO ((float*) X) |
| 38 | FOO = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}} |
Chris Lattner | ca354fa | 2008-11-17 19:51:54 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Chris Lattner | b1b4d33 | 2008-11-21 18:27:34 +0000 | [diff] [blame] | 41 | void test6() { |
| 42 | int X; |
| 43 | X(); // expected-error {{called object type 'int' is not a function or function pointer}} |
| 44 | } |
Chris Lattner | 7ca1425 | 2008-11-22 19:57:03 +0000 | [diff] [blame] | 45 | |
| 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')}} |
| 48 | } |
| 49 | |
Chris Lattner | 670a62c | 2008-12-12 05:35:08 +0000 | [diff] [blame] | 50 | |
| 51 | // rdar://6095061 |
| 52 | int test8(void) { |
| 53 | int i; |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 54 | __builtin_choose_expr (0, 42, i) = 10; |
Chris Lattner | 670a62c | 2008-12-12 05:35:08 +0000 | [diff] [blame] | 55 | return i; |
| 56 | } |
Chris Lattner | 31e21e0 | 2009-01-24 20:17:12 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | // PR3386 |
| 60 | struct f { int x : 4; float y[]; }; |
| 61 | int test9(struct f *P) { |
Chris Lattner | da02747 | 2009-01-24 21:29:22 +0000 | [diff] [blame] | 62 | int R; |
Anders Carlsson | 31fddcc | 2009-09-14 22:00:20 +0000 | [diff] [blame] | 63 | R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}} |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 64 | R = __alignof(P->y); // ok. |
Anders Carlsson | 31fddcc | 2009-09-14 22:00:20 +0000 | [diff] [blame] | 65 | R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}} |
Chris Lattner | da02747 | 2009-01-24 21:29:22 +0000 | [diff] [blame] | 66 | return R; |
Chris Lattner | 31e21e0 | 2009-01-24 20:17:12 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Chris Lattner | 56cd21b | 2009-02-13 22:08:30 +0000 | [diff] [blame] | 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. |
| 75 | } |
Chris Lattner | d0344a4 | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | #define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) |
| 79 | |
| 80 | struct mystruct {int A; }; |
Chris Lattner | 55660a7 | 2009-03-08 19:39:53 +0000 | [diff] [blame] | 81 | void test11(struct mystruct P, float F) { |
Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 82 | MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof (P)' (aka 'struct mystruct') and 'typeof (F)' (aka 'float'))}} |
Chris Lattner | d0344a4 | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | 55660a7 | 2009-03-08 19:39:53 +0000 | [diff] [blame] | 85 | // PR3753 |
| 86 | int test12(const char *X) { |
Ted Kremenek | 03a4bee | 2010-04-09 20:26:53 +0000 | [diff] [blame] | 87 | return X == "foo"; // expected-warning {{comparison against a string literal is unspecified (use strncmp instead)}} |
Chris Lattner | 55660a7 | 2009-03-08 19:39:53 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Douglas Gregor | d1e4d9b | 2010-01-12 23:18:54 +0000 | [diff] [blame] | 90 | int test12b(const char *X) { |
| 91 | return sizeof(X == "foo"); // no-warning |
| 92 | } |
| 93 | |
Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 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}} |
| 99 | } |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 100 | |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 101 | void test14() { |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 102 | typedef long long __m64 __attribute__((__vector_size__(8))); |
| 103 | typedef short __v4hi __attribute__((__vector_size__(8))); |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 9c10fcf | 2009-07-08 01:08:03 +0000 | [diff] [blame] | 105 | // Ok. |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 106 | __v4hi a; |
Chris Lattner | 9c10fcf | 2009-07-08 01:08:03 +0000 | [diff] [blame] | 107 | __m64 mask = (__m64)((__v4hi)a > (__v4hi)a); |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Chris Lattner | 0a026af | 2009-10-20 05:36:05 +0000 | [diff] [blame] | 110 | |
| 111 | // PR5242 |
| 112 | typedef unsigned long *test15_t; |
| 113 | |
| 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')}} |
| 116 | } |
| 117 | |
Chris Lattner | 02dd4b1 | 2009-12-05 05:40:13 +0000 | [diff] [blame] | 118 | // rdar://7446395 |
| 119 | void test16(float x) { x == ((void*) 0); } // expected-error {{invalid operands to binary expression}} |
Chris Lattner | 0a026af | 2009-10-20 05:36:05 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 7ef655a | 2010-01-12 21:23:57 +0000 | [diff] [blame] | 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}} |
Chris Lattner | cb329c5 | 2010-01-12 21:30:55 +0000 | [diff] [blame] | 127 | |
| 128 | x = sizeof(x/0); // no warning. |
Chris Lattner | 7ef655a | 2010-01-12 21:23:57 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Eric Christopher | c5e869b | 2010-04-19 18:39:43 +0000 | [diff] [blame] | 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}} |
| 136 | } |