Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 2 | |
| 3 | void test() { |
Argyrios Kyrtzidis | 4c0f56b | 2008-09-10 23:34:50 +0000 | [diff] [blame] | 4 | int x; |
| 5 | if (x) ++x; |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 6 | if (int x=0) ++x; |
| 7 | |
| 8 | typedef int arr[10]; |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 9 | while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{array initializer must be an initializer list}} |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 10 | while (int f()=0) ; // expected-error {{a function type is not allowed here}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 11 | |
| 12 | struct S {} s; |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 13 | if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} |
| 14 | while (struct S x=s) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} |
| 15 | do ; while (s); // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} |
| 16 | for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 17 | switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 18 | |
Argyrios Kyrtzidis | db7abf7 | 2011-06-28 03:01:12 +0000 | [diff] [blame] | 19 | while (struct NewS *x=0) ; |
Argyrios Kyrtzidis | 2ba68b2 | 2011-06-28 03:01:09 +0000 | [diff] [blame] | 20 | while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}} |
| 21 | while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}} |
Enea Zaffanella | 601e6e8 | 2013-01-11 14:34:39 +0000 | [diff] [blame] | 22 | switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} \ |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 23 | // expected-warning{{enumeration value 'E' not handled in switch}} expected-warning {{switch statement has empty body}} \ |
| 24 | // expected-note{{put the semicolon on a separate line}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 25 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 26 | if (int x=0) { // expected-note 2 {{previous definition is here}} |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 27 | int x; // expected-error {{redefinition of 'x'}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 28 | } |
| 29 | else |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 30 | int x; // expected-error {{redefinition of 'x'}} |
| 31 | while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 32 | while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 33 | for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 34 | for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 35 | for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 36 | for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 37 | switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 38 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 39 | |
| 40 | int* get_int_ptr(); |
| 41 | |
| 42 | void test2() { |
| 43 | float *ip; |
| 44 | if (int *ip = ip) { |
| 45 | } |
| 46 | } |
John McCall | abc56c7 | 2010-12-04 06:09:13 +0000 | [diff] [blame] | 47 | |
| 48 | // Make sure we do function/array decay. |
| 49 | void test3() { |
| 50 | if ("help") |
| 51 | (void) 0; |
| 52 | |
David Blaikie | 2def773 | 2011-12-09 21:42:37 +0000 | [diff] [blame] | 53 | if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}} \ |
| 54 | expected-note {{prefix with the address-of operator to silence this warning}} |
John McCall | abc56c7 | 2010-12-04 06:09:13 +0000 | [diff] [blame] | 55 | (void) 0; |
| 56 | } |
Richard Trieu | 26b45d8 | 2011-12-06 04:48:01 +0000 | [diff] [blame] | 57 | |
| 58 | void test4(bool (&x)(void)) { |
| 59 | while (x); |
| 60 | } |
Enea Zaffanella | 601e6e8 | 2013-01-11 14:34:39 +0000 | [diff] [blame] | 61 | |
| 62 | template <class> |
| 63 | void test5() { |
| 64 | if (struct S {}* p = 0) // expected-error {{types may not be defined in conditions}} |
| 65 | ; |
| 66 | } |
| 67 | void test5_inst() { |
| 68 | test5<int>(); |
| 69 | } |