Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -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]; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 9 | while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{initialization with '{...}' expected for array}} |
| 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 | |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 19 | while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize 'x' with an rvalue of type 'int'}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} |
| 20 | while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize 'x' with an rvalue of type 'int'}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 21 | switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{incompatible type}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 22 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 23 | if (int x=0) { // expected-note 2 {{previous definition is here}} |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 24 | int x; // expected-error {{redefinition of 'x'}} |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 25 | } |
| 26 | else |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 27 | int x; // expected-error {{redefinition of 'x'}} |
| 28 | while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 29 | while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 30 | for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 31 | for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 32 | for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 33 | for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}} |
| 34 | 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] | 35 | } |