[pushed,3/4] c++: fix in-charge parm in constexpr

Message ID 20231213164740.1591535-3-jason@redhat.com
State Committed
Commit e0659b5417b7f8a090ad2ed4dea830f11ef9c877
Headers
Series [pushed,1/4] c++: copy location to AGGR_INIT_EXPR |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged

Commit Message

Jason Merrill Dec. 13, 2023, 4:47 p.m. UTC
  Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

I was puzzled by the proposed patch for PR71093 specifically ignoring the
in-charge parameter; the problem turned out to be that when
cxx_eval_call_expression jumps from the clone to the cloned function, it
assumes that the latter has the same parameters, and so the in-charge parm
doesn't get an argument.  Since a class with vbases can't have constexpr
'tors there isn't actually a need for an in-charge parameter in a
destructor, but we used to use it for deleting destructors and never removed
it.  I have a patch to do that for GCC 15, but for now let's work around it.

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_call_expression): Handle missing in-charge
	argument.
---
 gcc/cp/constexpr.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Patch

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 4cf9dd71b05..9d9e96c2afd 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -3169,6 +3169,19 @@  cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 	      ctx->global->put_value (remapped, arg);
 	      remapped = DECL_CHAIN (remapped);
 	    }
+	  for (; remapped; remapped = TREE_CHAIN (remapped))
+	    if (DECL_NAME (remapped) == in_charge_identifier)
+	      {
+		/* FIXME destructors unnecessarily have in-charge parameters
+		   even in classes without vbases, map it to 0 for now.  */
+		gcc_assert (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fun)));
+		ctx->global->put_value (remapped, integer_zero_node);
+	      }
+	    else
+	      {
+		gcc_assert (seen_error ());
+		*non_constant_p = true;
+	      }
 	  /* Add the RESULT_DECL to the values map, too.  */
 	  gcc_assert (!DECL_BY_REFERENCE (res));
 	  ctx->global->put_value (res, NULL_TREE);