blob: 7931d11d14de962f39f366c2b81ab464d1a102c0 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00002
3void test() {
Argyrios Kyrtzidis4c0f56b2008-09-10 23:34:50 +00004 int x;
5 if (x) ++x;
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00006 if (int x=0) ++x;
7
8 typedef int arr[10];
Eli Friedmancfdc81a2009-12-19 08:11:05 +00009 while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{array initializer must be an initializer list}}
Chris Lattner5f4a6822008-11-23 23:12:31 +000010 while (int f()=0) ; // expected-error {{a function type is not allowed here}}
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +000011
12 struct S {} s;
Douglas Gregor09f41cf2009-01-14 15:45:31 +000013 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 Lattner5f4a6822008-11-23 23:12:31 +000017 switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +000018
John McCallb1622a12010-01-06 09:43:14 +000019 while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate is the implicit copy constructor}}
20 while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} expected-note{{candidate is the implicit copy constructor}}
Eli Friedmancfdc81a2009-12-19 08:11:05 +000021 switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}}
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +000022
Sebastian Redl3cb06922009-02-07 19:52:04 +000023 if (int x=0) { // expected-note 2 {{previous definition is here}}
Chris Lattner5f4a6822008-11-23 23:12:31 +000024 int x; // expected-error {{redefinition of 'x'}}
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +000025 }
26 else
Chris Lattner5f4a6822008-11-23 23:12:31 +000027 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 Kyrtzidis59210932008-09-10 02:17:11 +000035}
Douglas Gregor99e9b4d2009-11-25 00:27:52 +000036
37int* get_int_ptr();
38
39void test2() {
40 float *ip;
41 if (int *ip = ip) {
42 }
43}