xref: /aosp_15_r20/external/clang/test/Parser/cxx0x-condition.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2*67e74705SXin Li 
3*67e74705SXin Li struct S { S(int); operator bool(); };
4*67e74705SXin Li 
f()5*67e74705SXin Li void f() {
6*67e74705SXin Li   int a;
7*67e74705SXin Li   typedef int n;
8*67e74705SXin Li 
9*67e74705SXin Li   while (a) ;
10*67e74705SXin Li   while (int x) ; // expected-error {{variable declaration in condition must have an initializer}}
11*67e74705SXin Li   while (float x = 0) ;
12*67e74705SXin Li   if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
13*67e74705SXin Li   switch (int x = a+10) {}
14*67e74705SXin Li   for (; int x = ++a; ) ;
15*67e74705SXin Li 
16*67e74705SXin Li   if (S(a)) {} // ok
17*67e74705SXin Li   if (S(a) = 0) {} // ok
18*67e74705SXin Li   if (S(a) == 0) {} // ok
19*67e74705SXin Li 
20*67e74705SXin Li   if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}}
21*67e74705SXin Li   if (S(n) = 0) {} // ok
22*67e74705SXin Li   if (S(n) == 0) {} // expected-error {{unexpected type name 'n': expected expression}}
23*67e74705SXin Li 
24*67e74705SXin Li   if (S b(a)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}}
25*67e74705SXin Li 
26*67e74705SXin Li   if (S b(n)) {} // expected-error {{a function type is not allowed here}}
27*67e74705SXin Li   if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}}
28*67e74705SXin Li   if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}}
29*67e74705SXin Li 
30*67e74705SXin Li   S s(a);
31*67e74705SXin Li   if (S{s}) {} // ok
32*67e74705SXin Li   if (S a{s}) {} // ok
33*67e74705SXin Li   if (S a = {s}) {} // ok
34*67e74705SXin Li   if (S a == {s}) {} // expected-error {{did you mean '='?}}
35*67e74705SXin Li 
36*67e74705SXin Li   if (S(b){a}) {} // ok
37*67e74705SXin Li   if (S(b) = {a}) {} // ok
38*67e74705SXin Li }
39