-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 42104 |
| Resolution | FIXED |
| Resolved on | Jun 02, 2019 23:02 |
| Version | trunk |
| OS | Linux |
| CC | @hfinkel,@zygoloid |
Extended Description
When a lambda is created within another lambda, both with variadic arguments,
and the arguments of the enclosing lambda should be captured by an [&] in the inner, certain parameter pack expansions result in the following error:
error: reference to local variable 'one' declared in enclosing lambda expression
The problematic expansions seem to be those when there is an element wise operation with another parameter pack.
Note that the simple expansion of one... does compile, and so does (if we go to C++17) return (((one * ...) * two) + ...);
Also note that, when capturing [&one...] explicitly, everything compiles.
See the example code here:
#include
int main () {
auto first = [&] (auto... one) {
auto faulty = [&] (auto... two) {
//doesn't compile
return std::tuple<decltype(one)...>{(one * two)...};
//does compile
//return std::tuple<decltype(one)...>{one...};
};
auto working = [&one...] (auto ... three) {
//when explicitly capturing one..., it works
return std::tuple<decltype(one)...>{(one * three)...};
};
working(one...);
faulty(one...);
};
first(5,1);
}
See the example on
https://godbolt.org/z/nSt0cz