* [pushed] c++: static lambda in template [PR108526]
@ 2023-01-24 22:11 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-01-24 22:11 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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.
---
gcc/cp/pt.cc | 5 +++++
gcc/testsuite/g++.dg/cpp23/static-operator-call5.C | 8 ++++++++
2 files changed, 13 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp23/static-operator-call5.C
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>();
base-commit: 049a52909075117f5112971cc83952af2a818bc1
--
2.31.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-24 22:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 22:11 [pushed] c++: static lambda in template [PR108526] Jason Merrill
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).