Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 | |
| 3 | struct S { S(int); operator bool(); }; |
| 4 | |
| 5 | void 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 Smith | ac63d63 | 2017-09-29 23:57:25 +0000 | [diff] [blame] | 17 | if (S(a) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}} |
Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 18 | if (S(a) == 0) {} // ok |
| 19 | |
| 20 | if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}} |
Richard Smith | ac63d63 | 2017-09-29 23:57:25 +0000 | [diff] [blame] | 21 | if (S(n) = 0) {} // expected-warning {{redundant parentheses}} expected-note 2{{}} |
Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 22 | 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 Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 26 | if (S b(n)) {} // expected-error {{a function type is not allowed here}} |
Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 27 | if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}} |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 28 | if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}} |
Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 29 | |
Richard Trieu | 3267347 | 2012-10-01 17:39:51 +0000 | [diff] [blame] | 30 | 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 Smith | 1e3b0f0 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 35 | |
| 36 | if (S(b){a}) {} // ok |
| 37 | if (S(b) = {a}) {} // ok |
Richard Smith | 2a15b74 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 38 | } |