blob: 3d119ef8e709cb9bc0ab29f89c7c628aa425ba3e [file] [log] [blame]
Richard Smithc7a05a92016-06-29 21:17:59 +00001// RUN: %clang_cc1 -std=c++1z -verify %s -Wno-vexing-parse
2
3int g, h;
4typedef int T;
5int f() {
6 // init-statement declarations
Richard Smitha547eb22016-07-14 00:11:03 +00007 if (T n = 0; n != 0) {}
8 if (T f(); f()) {}
9 if (T(f()); f()) {}
10 if (T(f()), g, h; f()) {}
11 if (T f(); f()) {}
12 if (T f(), g, h; f()) {}
13 if (T(n) = 0; n) {}
Richard Smithc7a05a92016-06-29 21:17:59 +000014
15 // init-statement expressions
Richard Smitha547eb22016-07-14 00:11:03 +000016 if (T{f()}; f()) {}
17 if (T{f()}, g, h; f()) {} // expected-warning 2{{unused}}
18 if (T(f()), g, h + 1; f()) {} // expected-warning 2{{unused}}
Richard Smithc7a05a92016-06-29 21:17:59 +000019
20 // condition declarations
21 if (T(n){g}) {}
22 if (T f()) {} // expected-error {{function type}}
23 if (T f(), g, h) {} // expected-error {{function type}}
Richard Smithb8c414c2016-06-30 20:24:30 +000024 if (T(n) = 0) {}
Richard Smithc7a05a92016-06-29 21:17:59 +000025
26 // condition expressions
27 if (T(f())) {}
28 if (T{f()}) {}
29 if (T(f()), g, h) {} // expected-warning 2{{unused}}
30 if (T{f()}, g, h) {} // expected-warning 2{{unused}}
31
Richard Smithb8c414c2016-06-30 20:24:30 +000032 // none of the above, disambiguated as expression (can't be a declaration)
33 if (T(n)(g)) {} // expected-error {{undeclared identifier 'n'}}
34 if (T(n)(int())) {} // expected-error {{undeclared identifier 'n'}}
Richard Smithc7a05a92016-06-29 21:17:59 +000035
36 // Likewise for 'switch'
Richard Smitha547eb22016-07-14 00:11:03 +000037 switch (int n; n) {}
38 switch (g; int g = 5) {}
Richard Smithc7a05a92016-06-29 21:17:59 +000039
Richard Smitha547eb22016-07-14 00:11:03 +000040 if (int a, b; int c = a) { // expected-note 6{{previous}}
Richard Smithc7a05a92016-06-29 21:17:59 +000041 int a; // expected-error {{redefinition}}
42 int b; // expected-error {{redefinition}}
43 int c; // expected-error {{redefinition}}
44 } else {
45 int a; // expected-error {{redefinition}}
46 int b; // expected-error {{redefinition}}
47 int c; // expected-error {{redefinition}}
48 }
Richard Smitha547eb22016-07-14 00:11:03 +000049
50 return 0;
Richard Smithc7a05a92016-06-29 21:17:59 +000051}