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