| 1 |
// RUN: %clang_cc1 -std=c++2a -verify %s |
| 2 |
|
| 3 |
template<typename ...T, typename ...Lambda> void check_sizes(Lambda ...L) { |
| 4 |
static_assert(((sizeof(T) == sizeof(Lambda)) && ...)); |
| 5 |
} |
| 6 |
|
| 7 |
template<typename ...T> void f(T ...v) { |
| 8 |
// Pack expansion of lambdas: each lambda captures only one pack element. |
| 9 |
check_sizes<T...>([=] { (void)&v; } ...); |
| 10 |
|
| 11 |
// Pack expansion inside lambda: captures all pack elements. |
| 12 |
auto l = [=] { ((void)&v, ...); }; |
| 13 |
static_assert(sizeof(l) >= (sizeof(T) + ...)); |
| 14 |
} |
| 15 |
|
| 16 |
template void f(int, char, double); |
| 17 |
|
| 18 |
namespace PR41576 { |
| 19 |
template <class... Xs> constexpr int f(Xs ...xs) { |
| 20 |
return [&](auto ...ys) { // expected-note {{instantiation}} |
| 21 |
return ((xs + ys), ...); // expected-warning {{left operand of comma operator has no effect}} |
| 22 |
}(1, 2); |
| 23 |
} |
| 24 |
static_assert(f(3, 4) == 6); // expected-note {{instantiation}} |
| 25 |
} |