https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92912

            Bug ID: 92912
           Summary: Bad diagnostic for capture of this in free function
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: soko.slav at yandex dot ru
  Target Milestone: ---

This free function

void foo()
{
    [&]()
    {
        static_cast<void*>(this);
    };
}

does not compile but the message is misleading:

error: 'this' was not captured for this lambda function
static_cast<void*>(this);

Actually 'this' cannot be captured here as 'this' is keyword which cannot be
used in this context.

Expected message:
error: invalid use of 'this' in non-member function

tested locally and on https://godbolt.org/z/5cAA3k (more examples there
including similar case without lambda)

Reply via email to