blob: 73f3dceef64e16dccef5ada00344fd0413e6f9b4 [file] [log] [blame]
Richard Smith27d807c2013-04-30 13:56:41 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %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];
Richard Smith27d807c2013-04-30 13:56:41 +00009 while (arr x={0}) ; // expected-error {{an array type is not allowed here}}
Richard Smith943c4402012-07-30 21:30:52 +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}}
Richard Smith27d807c2013-04-30 13:56:41 +000022 switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000023
Sebastian Redl2175b6a2009-02-07 19:52:04 +000024 if (int x=0) { // expected-note 2 {{previous definition is here}}
Chris Lattner0369c572008-11-23 23:12:31 +000025 int x; // expected-error {{redefinition of 'x'}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000026 }
27 else
Chris Lattner0369c572008-11-23 23:12:31 +000028 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}}
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +000036}
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000037
38int* get_int_ptr();
39
40void test2() {
41 float *ip;
42 if (int *ip = ip) {
43 }
44}
John McCall29cb2fd2010-12-04 06:09:13 +000045
46// Make sure we do function/array decay.
47void test3() {
48 if ("help")
49 (void) 0;
50
David Blaikie10eb4b62011-12-09 21:42:37 +000051 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}}
John McCall29cb2fd2010-12-04 06:09:13 +000053 (void) 0;
54}
Richard Trieu5f623222011-12-06 04:48:01 +000055
56void test4(bool (&x)(void)) {
57 while (x);
58}
Enea Zaffanella29e1c4b2013-01-11 14:34:39 +000059
60template <class>
61void test5() {
62 if (struct S {}* p = 0) // expected-error {{types may not be defined in conditions}}
63 ;
64}
65void test5_inst() {
66 test5<int>();
67}