Skip to content

Commit d30c84b

Browse files
authored
Update cxx1y-init-captures.cpp
1 parent e6ec625 commit d30c84b

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

clang/test/SemaCXX/cxx1y-init-captures.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44
namespace variadic_expansion {
55
int f(int &, char &) { return 0; }
66
template<class ... Ts> char fv(Ts ... ts) { return 0; }
7-
template <typename ... T> void g(T &... t) {
8-
f([&a(t)]()->decltype(auto) { // Line 8
7+
// FIXME: why do we get 2 error messages
8+
template <typename ... T> void g(T &... t) { //expected-note3{{declared here}}
9+
f([&a(t)]()->decltype(auto) {
910
return a;
10-
}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
11+
}() ...);
1112

12-
auto L = [x = undeclared_var()]() { return x; }; // expected-error {{use of undeclared identifier 'undeclared_var'}}
13+
auto L = [x = f([&a(t)]()->decltype(auto) { return a; }()...)]() { return x; };
1314
const int y = 10;
1415
auto M = [x = y,
1516
&z = y](T& ... t) { };
1617
auto N = [x = y,
1718
&z = y, n = f(t...),
18-
o = undeclared_var(), t...](T& ... s) { // expected-error {{use of undeclared identifier 'undeclared_var'}}
19+
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...), t...](T& ... s) {
1920
fv([&a(t)]()->decltype(auto) {
2021
return a;
21-
}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
22+
}() ...);
2223
};
23-
auto N2 = [x = y,
24-
&z = y, n = f(t...),
25-
o = undeclared_var(), &t...](T& ... s) { // expected-error {{use of undeclared identifier 'undeclared_var'}}
26-
fv([&a(t), &t...]() -> decltype(auto) {
24+
auto N2 = [x = y, //expected-note3{{begins here}} expected-note 6 {{default capture by}}
25+
&z = y, n = f(t...),
26+
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...)](T& ... s) { // expected-note 6 {{capture 't' by}} expected-note {{substituting into a lambda}}
27+
fv([&a(t)]()->decltype(auto) { //expected-error 3{{captured}}
2728
return a;
28-
}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
29-
};
29+
}() ...);
30+
};
31+
3032
}
3133

32-
void h(int i, char c) { g(i, c); }
34+
void h(int i, char c) { g(i, c); } // expected-note {{requested here}}
3335
}
3436

3537
namespace odr_use_within_init_capture {
@@ -49,7 +51,7 @@ int test() {
4951
{ // should not capture
5052
const int x = 10;
5153
auto L = [&z = x](int a) {
52-
return a;
54+
return a;;
5355
};
5456

5557
}
@@ -109,7 +111,7 @@ int test(T t = T{}) {
109111
{ // should not capture
110112
const T x = 10;
111113
auto L = [&z = x](T a) {
112-
return a;
114+
return a;;
113115
};
114116

115117
}
@@ -183,7 +185,8 @@ void h() {
183185
}
184186

185187
int run() {
186-
return 0;
188+
f<int>();
189+
h<int>();
187190
}
188191

189192
}
@@ -205,7 +208,7 @@ void test(double weight) {
205208
}
206209

207210
namespace init_capture_undeclared_identifier {
208-
auto a = [x = y]{}; // expected-error{{use of undeclared identifier 'y'}} expected-error{{invalid initializer type for lambda capture}}
211+
auto a = [x = y]{}; // expected-error{{use of undeclared identifier 'y'}}
209212

210213
int typo_foo; // expected-note 2 {{'typo_foo' declared here}}
211214
auto b = [x = typo_boo]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}}

0 commit comments

Comments
 (0)