1 // RUN: %clang_cc1 -std=c++2a -verify %s
2
3 namespace p3 {
4 void bar(...);
foo(Args...args)5 template <typename... Args> void foo(Args... args) {
6 (void)[... xs = args] {
7 bar(xs...);
8 };
9 }
10
use()11 void use() {
12 foo();
13 foo(1);
14 }
15 }
16
f(T...t)17 template<typename ...T> void f(T ...t) {
18 (void)[&...x = t] {
19 x; // expected-error {{unexpanded parameter pack 'x'}}
20 };
21
22 // Not OK: can't expand 'x' outside its scope.
23 weird((void)[&...x = t] {
24 return &x; // expected-error {{unexpanded parameter pack 'x'}}
25 }... // expected-error {{does not contain any unexpanded}}
26 );
27
28 // OK, capture only one 'slice' of 'x'.
29 weird((void)[&x = t] {
30 return &x;
31 }...
32 );
33
34 // 'x' is not expanded by the outer '...', but 'T' is.
35 weird((void)[&... x = t] {
36 return T() + &x; // expected-error {{unexpanded parameter pack 'x'}}
37 }... // expected-error {{does not contain any unexpanded}}
38 );
39 }
40
__anonaa328ce30602(auto F) 41 template<int ...a> constexpr auto x = [...z = a] (auto F) { return F(z...); };
__anonaa328ce30702(int a, int b, int c) 42 static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
__anonaa328ce30802(int a, int b, int c) 43 static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}
44
__anonaa328ce30902(auto F) 45 template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{must appear before the name of the capture}}
__anonaa328ce30a02(int a, int b, int c) 46 static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
__anonaa328ce30b02(int a, int b, int c) 47 static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}
48