[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx1z-init-statement.cpp
blob157e2b5f2ee55c7048227ae3a7c4b9f3f665b3b9
1 // RUN: %clang_cc1 -std=c++1z -verify %s -Wno-vexing-parse
3 int g, h;
4 typedef int T;
5 int f() {
6 // init-statement declarations
7 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) {}
15 // init-statement expressions
16 if (T{f()}; f()) {} // expected-warning {{expression result unused}}
17 if (T{f()}, g, h; f()) {} // expected-warning 2{{left operand of comma operator has no effect}} expected-warning {{expression result unused}}
18 if (T(f()), g, h + 1; f()) {} // expected-warning 2{{left operand of comma operator has no effect}} expected-warning {{expression result unused}}
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}}
24 if (T(n) = 0) {}
26 // condition expressions
27 if (T(f())) {}
28 if (T{f()}) {}
29 if (T(f()), g, h) {} // expected-warning 2{{left operand of comma operator has no effect}}
30 if (T{f()}, g, h) {} // expected-warning 2{{left operand of comma operator has no effect}}
32 // 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'}}
36 // Likewise for 'switch'
37 switch (int n; n) {}
38 switch (g; int g = 5) {} // expected-warning {{expression result unused}}
40 if (int a, b; int c = a) { // expected-note 6{{previous}}
41 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}}
50 return 0;