| 1 |
// RUN: %clang_cc1 -std=c++2a -verify %s |
| 2 |
|
| 3 |
namespace p3 { |
| 4 |
void bar(...); |
| 5 |
template <typename... Args> void foo(Args... args) { |
| 6 |
(void)[... xs = args] { |
| 7 |
bar(xs...); |
| 8 |
}; |
| 9 |
} |
| 10 |
|
| 11 |
void use() { |
| 12 |
foo(); |
| 13 |
foo(1); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 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 |
|
| 41 |
template<int ...a> constexpr auto x = [...z = a] (auto F) { return F(z...); }; |
| 42 |
static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123); |
| 43 |
static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}} \ |
| 44 |
// expected-note {{evaluates to '123 == 124'}} |
| 45 |
|
| 46 |
template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{must appear before the name of the capture}} |
| 47 |
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123); |
| 48 |
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}} \ |
| 49 |
// expected-note {{evaluates to '123 == 124'}} |