[llvm-bugs] [Bug 41410] New: Misleading error message 'this' was not captured for this lambda function

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 6 10:20:31 PDT 2019


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

            Bug ID: 41410
           Summary: Misleading error message 'this' was not captured for
                    this lambda function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gabriel.aubut-lussier at outlook.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

The error message given when 'this' cannot be captured is misleading in the
sense that it points the user to the lambda that fails to capture 'this' rather
than raise questions about why it fails to do so.

The icc compiler does the best job of giving context with this error. MSVC also
displays a bit more information. Clang has the worst offender. GCC could use a
bit of improvement. Aiming for an error message that is closer to icc seems
like the ideal solution. The error message given by icc is the following:
error: this enclosing-function local variable cannot be referenced in this
lambda body because an enclosing lambda does not allow implicit captures

Godbolt : https://gcc.godbolt.org/z/rmefHT
Sample code for the issue:

struct S
{
    void f() {
        []() {
            [this]() {

            }();
        }();
    }
};

int main()
{
    S s;
    s.f();
}

-- 
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/20190406/4581ca89/attachment.html>


More information about the llvm-bugs mailing list