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.
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);
--- /dev/null
+// PR c++/108526
+// { dg-do compile { target c++23 } }
+
+template<class> void f()
+{
+ auto a = [] (auto x) static { return x; };
+}
+template void f<int>();