[llvm-bugs] [Bug 42104] New: implicit [&] parameter pack capture in lambda gives error
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jun 2 03:32:15 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42104
Bug ID: 42104
Summary: implicit [&] parameter pack capture in lambda gives
error
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: niklas at nolte.dev
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
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 <tuple>
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190602/ac5a0d4e/attachment.html>
More information about the llvm-bugs
mailing list