xref: /llvm-project/clang/test/Parser/cxx0x-condition.cpp (revision ac63d63543ca824434236ffd788c46eec9339657)
12a15b746SRichard Smith // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
22a15b746SRichard Smith 
32a15b746SRichard Smith struct S { S(int); operator bool(); };
42a15b746SRichard Smith 
f()52a15b746SRichard Smith void f() {
62a15b746SRichard Smith   int a;
72a15b746SRichard Smith   typedef int n;
82a15b746SRichard Smith 
92a15b746SRichard Smith   while (a) ;
102a15b746SRichard Smith   while (int x) ; // expected-error {{variable declaration in condition must have an initializer}}
112a15b746SRichard Smith   while (float x = 0) ;
122a15b746SRichard Smith   if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
132a15b746SRichard Smith   switch (int x = a+10) {}
142a15b746SRichard Smith   for (; int x = ++a; ) ;
152a15b746SRichard Smith 
162a15b746SRichard Smith   if (S(a)) {} // ok
17*ac63d635SRichard Smith   if (S(a) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}}
182a15b746SRichard Smith   if (S(a) == 0) {} // ok
192a15b746SRichard Smith 
202a15b746SRichard Smith   if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}}
21*ac63d635SRichard Smith   if (S(n) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}}
222a15b746SRichard Smith   if (S(n) == 0) {} // expected-error {{unexpected type name 'n': expected expression}}
232a15b746SRichard Smith 
242a15b746SRichard Smith   if (S b(a)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}}
252a15b746SRichard Smith 
2603a4aa3dSRichard Smith   if (S b(n)) {} // expected-error {{a function type is not allowed here}}
272a15b746SRichard Smith   if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}}
2803a4aa3dSRichard Smith   if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}}
292a15b746SRichard Smith 
303267347cSRichard Trieu   S s(a);
313267347cSRichard Trieu   if (S{s}) {} // ok
323267347cSRichard Trieu   if (S a{s}) {} // ok
333267347cSRichard Trieu   if (S a = {s}) {} // ok
343267347cSRichard Trieu   if (S a == {s}) {} // expected-error {{did you mean '='?}}
351e3b0f06SRichard Smith 
361e3b0f06SRichard Smith   if (S(b){a}) {} // ok
371e3b0f06SRichard Smith   if (S(b) = {a}) {} // ok
382a15b746SRichard Smith }
39