blob: 21671fab3c04728c8feb21f59c1907eeb5638bb4 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00002
3void test() {
Argyrios Kyrtzidis996677e2008-09-10 23:34:50 +00004 int x;
5 if (x) ++x;
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00006 if (int x=0) ++x;
7
8 typedef int arr[10];
Eli Friedman78275202009-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 Lattner0369c572008-11-23 23:12:31 +000010 while (int f()=0) ; // expected-error {{a function type is not allowed here}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000011
12 struct S {} s;
Douglas Gregor5fb53972009-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 Lattner0369c572008-11-23 23:12:31 +000017 switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000018
Argyrios Kyrtzidis8ea7e582011-06-28 03:01:12 +000019 while (struct NewS *x=0) ;
Argyrios Kyrtzidis31daf432011-06-28 03:01:09 +000020 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}}
Douglas Gregor12ea0f42010-02-17 23:29:11 +000022 switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \
23 // expected-warning{{enumeration value 'E' not handled in switch}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000024
Sebastian Redl2175b6a2009-02-07 19:52:04 +000025 if (int x=0) { // expected-note 2 {{previous definition is here}}
Chris Lattner0369c572008-11-23 23:12:31 +000026 int x; // expected-error {{redefinition of 'x'}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000027 }
28 else
Chris Lattner0369c572008-11-23 23:12:31 +000029 int x; // expected-error {{redefinition of 'x'}}
30 while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
31 while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
32 for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
33 for (int x; ; ) 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 for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
36 switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000037}
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000038
39int* get_int_ptr();
40
41void test2() {
42 float *ip;
43 if (int *ip = ip) {
44 }
45}
John McCall29cb2fd2010-12-04 06:09:13 +000046
47// Make sure we do function/array decay.
48void test3() {
49 if ("help")
50 (void) 0;
51
Lang Hamesdf5c1212011-12-05 20:49:50 +000052 if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}}
John McCall29cb2fd2010-12-04 06:09:13 +000053 (void) 0;
54}