> and this in tsubst_lambda_expr that assumes iobj: > > /* Fix the type of 'this'. */ > fntype = build_memfn_type (fntype, type, > type_memfn_quals (fntype), > type_memfn_rqual (fntype));
Unfortunately, putting a condition on this had some unforeseen consequences. I've been working on this about 8 hours today and I'm a little defeated after discovering this. commit 39ade88fa1632c659c5c4ed065fa2b62d16a8670 Author: Jason Merrill <ja...@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: gcc/cp/ChangeLog: * pt.cc (tsubst_function_decl): Handle static lambda. gcc/testsuite/ChangeLog: * g++.dg/cpp23/static-operator-call5.C: New test. 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); + I discovered this when I decided to try a static lambda to see if that would help me narrow down my current problem. I was shocked to find out it exhibited the exact same ICE I was trying to fix. So I was going to go undo my changes one by one to see what it was, thankfully this was the first one I tried, I undid the condition I put on it, and the crash was gone. Anyway, this has been my whole day so far, I am going to have to look deeper to decide how exactly I fix this because I don't think this hack that is in place at the moment is the right way to do it. The first idea that comes to mind is modifying the decl_context of the call operator, but I'm really not sure. I'm just going to take a break, eat some pizza, and come back to this hopefully less defeated. Alex