blob: 19d5a7395d4173cc569acb58509a9a529b102cc8 [file] [log] [blame]
Richard Smith2a15b742012-02-22 06:49:09 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3struct S { S(int); operator bool(); };
4
5void f() {
6 int a;
7 typedef int n;
8
9 while (a) ;
10 while (int x) ; // expected-error {{variable declaration in condition must have an initializer}}
11 while (float x = 0) ;
12 if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
13 switch (int x = a+10) {}
14 for (; int x = ++a; ) ;
15
16 if (S(a)) {} // ok
Richard Smithac63d632017-09-29 23:57:25 +000017 if (S(a) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}}
Richard Smith2a15b742012-02-22 06:49:09 +000018 if (S(a) == 0) {} // ok
19
20 if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}}
Richard Smithac63d632017-09-29 23:57:25 +000021 if (S(n) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}}
Richard Smith2a15b742012-02-22 06:49:09 +000022 if (S(n) == 0) {} // expected-error {{unexpected type name 'n': expected expression}}
23
24 if (S b(a)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}}
25
Richard Smith03a4aa32016-06-23 19:02:52 +000026 if (S b(n)) {} // expected-error {{a function type is not allowed here}}
Richard Smith2a15b742012-02-22 06:49:09 +000027 if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}}
Richard Smith03a4aa32016-06-23 19:02:52 +000028 if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}}
Richard Smith2a15b742012-02-22 06:49:09 +000029
Richard Trieu32673472012-10-01 17:39:51 +000030 S s(a);
31 if (S{s}) {} // ok
32 if (S a{s}) {} // ok
33 if (S a = {s}) {} // ok
34 if (S a == {s}) {} // expected-error {{did you mean '='?}}
Richard Smith1e3b0f02012-02-23 01:36:12 +000035
36 if (S(b){a}) {} // ok
37 if (S(b) = {a}) {} // ok
Richard Smith2a15b742012-02-22 06:49:09 +000038}