1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
test()3 void test() {
4 int x;
5 if (x) ++x;
6 if (int x=0) ++x;
7
8 typedef int arr[10];
9 while (arr x={0}) ; // expected-error {{an array type is not allowed here}}
10 while (int f()=0) ; // expected-error {{a function type is not allowed here}}
11
12 struct S {} s;
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'}}
17 switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
18
19 while (struct NewS *x=0) ;
20 while (struct S {} *x=0) ; // expected-error {{'S' cannot be defined in a condition}}
21 while (struct {} *x=0) ; // expected-error-re {{'(anonymous struct at {{.*}})' cannot be defined in a condition}}
22 switch (enum {E} x=0) ; // expected-error-re {{'(anonymous enum at {{.*}})' cannot be defined in a condition}}
23
24 if (int x=0) { // expected-note 2 {{previous definition is here}}
25 int x; // expected-error {{redefinition of 'x'}}
26 }
27 else
28 int x; // expected-error {{redefinition of 'x'}}
29 while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
30 while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
31 for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
32 for (int x; ; ) 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 for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
35 switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
36 }
37
38 int* get_int_ptr();
39
test2()40 void test2() {
41 float *ip;
42 if (int *ip = ip) {
43 }
44 }
45
46 // Make sure we do function/array decay.
test3()47 void test3() {
48 if ("help")
49 (void) 0;
50
51 if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}} \
52 expected-note {{prefix with the address-of operator to silence this warning}}
53 (void) 0;
54 }
55
test4(bool (& x)(void))56 void test4(bool (&x)(void)) {
57 while (x);
58 }
59
60 template <class>
test5()61 void test5() {
62 if (struct S {}* p = 0) // expected-error {{'S' cannot be defined in a condition}}
63 ;
64 }
test5_inst()65 void test5_inst() {
66 test5<int>();
67 }
68
PR28373()69 void PR28373() {
70 if (!x) {} // expected-error {{undeclared}}
71 }
72