public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5334] c++: static lambda in template [PR108526]
Date: Tue, 24 Jan 2023 22:12:03 +0000 (GMT)	[thread overview]
Message-ID: <20230124221203.955403858439@sourceware.org> (raw)

https://gcc.gnu.org/g:39ade88fa1632c659c5c4ed065fa2b62d16a8670

commit r13-5334-g39ade88fa1632c659c5c4ed065fa2b62d16a8670
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jan 24 15:29:35 2023 -0500

    c++: static lambda in template [PR108526]
    
    tsubst_lambda_expr uses build_memfn_type to build a METHOD_TYPE for the new
    lamba op().  This is not what we want for a C++23 static op(), but since we
    also use that METHOD_TYPE to communicate the closure type down to
    tsubst_function_decl, let's wait and turn it back at that point.
    
            PR c++/108526
    
    gcc/cp/ChangeLog:
    
            * pt.cc (tsubst_function_decl): Handle static lambda.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp23/static-operator-call5.C: New test.

Diff:
---
 gcc/cp/pt.cc                                       | 5 +++++
 gcc/testsuite/g++.dg/cpp23/static-operator-call5.C | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2a4d03c5e47..51fc246ed71 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -14306,6 +14306,11 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
   tree ctx = closure ? closure : DECL_CONTEXT (t);
   bool member = ctx && TYPE_P (ctx);
 
+  /* If this is a static lambda, remove the 'this' pointer added in
+     tsubst_lambda_expr now that we know the closure type.  */
+  if (lambda_fntype && DECL_STATIC_FUNCTION_P (t))
+    lambda_fntype = static_fn_type (lambda_fntype);
+
   if (member && !closure)
     ctx = tsubst_aggr_type (ctx, args,
 			    complain, t, /*entering_scope=*/1);
diff --git a/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C b/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C
new file mode 100644
index 00000000000..ae022d0b971
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C
@@ -0,0 +1,8 @@
+// PR c++/108526
+// { dg-do compile { target c++23 } }
+
+template<class> void f()
+{
+  auto a = [] (auto x) static { return x; };
+}
+template void f<int>();

                 reply	other threads:[~2023-01-24 22:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230124221203.955403858439@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@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).