[llvm-bugs] [Bug 41576] New: Bogus "reference to local variable error" with lambda in fold expression over comma and assignment
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Apr 24 03:14:54 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41576
Bug ID: 41576
Summary: Bogus "reference to local variable error" with lambda
in fold expression over comma and assignment
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++'17
Assignee: unassignedclangbugs at nondot.org
Reporter: vittorio.romeo at outlook.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
The following code
#include <tuple>
template <class T>
struct X
{
template <class F>
void f(F f)
{
f(0);
}
};
template <class... Xs>
void bug(X<Xs>... xs)
{
std::tuple<Xs...> t;
std::apply([&](auto&... ys)
{
(xs.f([&](auto y)
{
ys = y;
}), ...);
}, t);
}
int main()
{
bug(X<int>{});
}
produces a bogus error with clang++ (version 9.0.0 (trunk 359058))
<source>:20:10: error: reference to local variable 'xs' declared in
enclosing function 'bug<int>'
(xs.f([&](auto y)
^
The bug can be reproduced on godbolt.org here:
https://gcc.godbolt.org/z/NNLI5p
---
Changing the lambda to the following
std::apply([&xs...](auto&... ys)
{
(xs.f([&ys...](auto y)
{
ys = y;
}), ...);
}, t);
fixes the error:
https://gcc.godbolt.org/z/hp2hMN
--
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/20190424/dc356660/attachment.html>
More information about the llvm-bugs
mailing list