From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 260C63858CDA; Tue, 23 Jan 2024 17:38:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 260C63858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706031538; bh=QfwsN8F13wZk1KGNfVXnmIV0dFugf56bek5hz/Tid7I=; h=From:To:Subject:Date:From; b=nlTujyUXd/++iy/Rj2EI07gcXGDMIDBIiLIQk8AaZUpwRjfihNAfoc/QjdPvwKQkT tU0Mv2+7pUJexCSryhNiyiV4CSY53JVsT8hYLXihCBrronHMoJH34skHnSwP2ywSfS XS2btqlYjP4JZpDVzVfyz4ST/9YgXbq9PjtV5q+M= From: "arthur.j.odwyer at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda Date: Tue, 23 Jan 2024 17:38:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arthur.j.odwyer at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113563 Bug ID: 113563 Summary: Rejects capture of `this` in C++23 `this auto` lambda Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arthur.j.odwyer at gmail dot com Target Milestone: --- // https://godbolt.org/z/KWv8n6zEG struct S { int x_; void f() { [this](this auto) { return this; }; } }; GCC trunk complains: :5:16: error: invalid use of 'this' in non-member function 5 | return this; | ^~~~ The error also happens with - [this](this auto&&) { return this; } - [this](this auto) { return x; } - [this](this auto) { f(); } - [&](this auto) { return this; } - [&](this auto) { return x; } - [&](this auto) { f(); } My understanding is that all of these lambdas should be well-formed, just as long as the lambda's call operator is eventually instantiated (if it's ever instantiated at all) with a type that satisfies [expr.prim.lambda.closure]/= 5, i.e. is either the closure type itself or a class type derived from the clo= sure type. Btw, I do like that GCC eagerly and SFINAE-friendlily rejects `[&](this T) = {}`. I hope fixing this bug doesn't require undoing that feature. (By "SFINAE-friendly" I mean https://godbolt.org/z/fK4f13343 ) See also https://quuxplusone.github.io/blog/2024/01/23/capturing-lambda-deducing-thi= s/=