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

            Bug ID: 116124
           Summary: Can't use captured 'this' in lambda function that
                    deduces this
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eddiejnolan at gmail dot com
  Target Milestone: ---

On the current GCC trunk and in version 14.1.0, GCC produces an error when the
user attempts to use a captured 'this' in a lambda function that deduces the
closure object in C++23 mode:

struct foo {
  void bar() {
    [this](this auto self) {
      return this;
    };
  }
};

The error message is:

<source>: In lambda function:
<source>:4:14: error: invalid use of 'this' in non-member function
    4 |       return this;
      |              ^~~~

Clang and MSVC both accept this code.

Compiler explorer link: https://godbolt.org/z/joKTb6x5j

Reply via email to