public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda @ 2024-01-23 17:38 arthur.j.odwyer at gmail dot com 2024-02-05 8:45 ` [Bug c++/113563] " de34 at live dot cn ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: arthur.j.odwyer at gmail dot com @ 2024-01-23 17:38 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113563 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: <source>: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 closure 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-this/ ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113563] Rejects capture of `this` in C++23 `this auto` lambda 2024-01-23 17:38 [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda arthur.j.odwyer at gmail dot com @ 2024-02-05 8:45 ` de34 at live dot cn 2024-02-07 14:56 ` ppalka at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: de34 at live dot cn @ 2024-02-05 8:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113563 Jiang An <de34 at live dot cn> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |de34 at live dot cn --- Comment #1 from Jiang An <de34 at live dot cn> --- (In reply to Arthur O'Dwyer from comment #0) > 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-this/ Hmm... after reading CWG2672 (https://cplusplus.github.io/CWG/issues/2672.html), I think the SFINAE-friendliness is actually required since the parameter list of a lambda expression is in the immediate context (only the lambda body is excluded). ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113563] Rejects capture of `this` in C++23 `this auto` lambda 2024-01-23 17:38 [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda arthur.j.odwyer at gmail dot com 2024-02-05 8:45 ` [Bug c++/113563] " de34 at live dot cn @ 2024-02-07 14:56 ` ppalka at gcc dot gnu.org 2024-02-07 15:00 ` ppalka at gcc dot gnu.org 2024-03-06 19:56 ` ppalka at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: ppalka at gcc dot gnu.org @ 2024-02-07 14:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113563 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hewillk at gmail dot com --- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> --- *** Bug 113810 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113563] Rejects capture of `this` in C++23 `this auto` lambda 2024-01-23 17:38 [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda arthur.j.odwyer at gmail dot com 2024-02-05 8:45 ` [Bug c++/113563] " de34 at live dot cn 2024-02-07 14:56 ` ppalka at gcc dot gnu.org @ 2024-02-07 15:00 ` ppalka at gcc dot gnu.org 2024-03-06 19:56 ` ppalka at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: ppalka at gcc dot gnu.org @ 2024-02-07 15:00 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113563 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ppalka at gcc dot gnu.org --- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> --- It works if we capture 'this' indirectly, e.g. via an init-capture: struct S { void f() { [this_=this](this auto) { return this_; }; } }; ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113563] Rejects capture of `this` in C++23 `this auto` lambda 2024-01-23 17:38 [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda arthur.j.odwyer at gmail dot com ` (2 preceding siblings ...) 2024-02-07 15:00 ` ppalka at gcc dot gnu.org @ 2024-03-06 19:56 ` ppalka at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: ppalka at gcc dot gnu.org @ 2024-03-06 19:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113563 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rl.alt.accnt at gmail dot com --- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> --- *** Bug 114257 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-06 19:56 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-01-23 17:38 [Bug c++/113563] New: Rejects capture of `this` in C++23 `this auto` lambda arthur.j.odwyer at gmail dot com 2024-02-05 8:45 ` [Bug c++/113563] " de34 at live dot cn 2024-02-07 14:56 ` ppalka at gcc dot gnu.org 2024-02-07 15:00 ` ppalka at gcc dot gnu.org 2024-03-06 19:56 ` ppalka at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).