2013-04-30 21:56:41 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2008-09-10 10:17:11 +08:00
|
|
|
|
|
|
|
void test() {
|
2008-09-11 07:34:50 +08:00
|
|
|
int x;
|
|
|
|
if (x) ++x;
|
2008-09-10 10:17:11 +08:00
|
|
|
if (int x=0) ++x;
|
|
|
|
|
|
|
|
typedef int arr[10];
|
2013-04-30 21:56:41 +08:00
|
|
|
while (arr x={0}) ; // expected-error {{an array type is not allowed here}}
|
2012-07-31 05:30:52 +08:00
|
|
|
while (int f()=0) ; // expected-error {{a function type is not allowed here}}
|
2008-09-10 10:17:11 +08:00
|
|
|
|
|
|
|
struct S {} s;
|
2009-01-14 23:45:31 +08:00
|
|
|
if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
|
|
|
|
while (struct S x=s) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
|
|
|
|
do ; while (s); // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
|
|
|
|
for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
|
2008-11-24 07:12:31 +08:00
|
|
|
switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
|
2008-09-10 10:17:11 +08:00
|
|
|
|
2011-06-28 11:01:12 +08:00
|
|
|
while (struct NewS *x=0) ;
|
2015-12-12 05:39:12 +08:00
|
|
|
while (struct S {} *x=0) ; // expected-error {{'S' cannot be defined in a condition}}
|
|
|
|
while (struct {} *x=0) ; // expected-error-re {{'(anonymous struct at {{.*}})' cannot be defined in a condition}}
|
|
|
|
switch (enum {E} x=0) ; // expected-error-re {{'(anonymous enum at {{.*}})' cannot be defined in a condition}}
|
2008-09-10 10:17:11 +08:00
|
|
|
|
2009-02-08 03:52:04 +08:00
|
|
|
if (int x=0) { // expected-note 2 {{previous definition is here}}
|
2008-11-24 07:12:31 +08:00
|
|
|
int x; // expected-error {{redefinition of 'x'}}
|
2008-09-10 10:17:11 +08:00
|
|
|
}
|
|
|
|
else
|
2008-11-24 07:12:31 +08:00
|
|
|
int x; // expected-error {{redefinition of 'x'}}
|
|
|
|
while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
|
|
|
switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
|
2008-09-10 10:17:11 +08:00
|
|
|
}
|
2009-11-25 08:27:52 +08:00
|
|
|
|
|
|
|
int* get_int_ptr();
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
float *ip;
|
|
|
|
if (int *ip = ip) {
|
|
|
|
}
|
|
|
|
}
|
2010-12-04 14:09:13 +08:00
|
|
|
|
|
|
|
// Make sure we do function/array decay.
|
|
|
|
void test3() {
|
|
|
|
if ("help")
|
|
|
|
(void) 0;
|
|
|
|
|
2011-12-10 05:42:37 +08:00
|
|
|
if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}} \
|
|
|
|
expected-note {{prefix with the address-of operator to silence this warning}}
|
2010-12-04 14:09:13 +08:00
|
|
|
(void) 0;
|
|
|
|
}
|
2011-12-06 12:48:01 +08:00
|
|
|
|
|
|
|
void test4(bool (&x)(void)) {
|
|
|
|
while (x);
|
|
|
|
}
|
2013-01-11 22:34:39 +08:00
|
|
|
|
|
|
|
template <class>
|
|
|
|
void test5() {
|
2015-12-12 05:39:12 +08:00
|
|
|
if (struct S {}* p = 0) // expected-error {{'S' cannot be defined in a condition}}
|
2013-01-11 22:34:39 +08:00
|
|
|
;
|
|
|
|
}
|
|
|
|
void test5_inst() {
|
|
|
|
test5<int>();
|
|
|
|
}
|