public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "arthur.j.odwyer at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-113563-4@http.gcc.gnu.org/bugzilla/> (raw)

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/

             reply	other threads:[~2024-01-23 17:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23 17:38 arthur.j.odwyer at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113563-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).