[llvm-bugs] [Bug 41165] New: invalid error: reference to local variable 'xxx' declared in enclosing lambda

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 20 18:59:40 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41165

            Bug ID: 41165
           Summary: invalid error: reference to local variable 'xxx'
                    declared in enclosing lambda
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++'17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jonathan.poelen at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

template<class... Ts>
void foo(Ts... xs)
{
    [&](auto&... lhs){
        [&](auto&... rhs){
            ((lhs = rhs), ...);
        }(xs...);
    }(xs...);
}

int main()
{
  foo(1);
}


test.cpp:6:15: error: reference to local variable 'lhs' declared in enclosing
lambda expression
            ((lhs = rhs), ...);
              ^


If lhs is captured explicitly, there is no error, but a warning:

test.cpp:5:11: warning: lambda capture 'lhs' is not used
[-Wunused-lambda-capture]
        [&lhs...](auto&... rhs){
          ^

(Works with GCC and MSVC)

-- 
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/20190321/314a3329/attachment.html>


More information about the llvm-bugs mailing list