c++: simplify TEMPLATE_TYPE_PARM level lowering

1. Don't bother recursing when level lowering a cv-qualified type
   template parameter.
2. Get rid of the recursive loop breaker when level lowering a
   constrained auto, and enable the TEMPLATE_PARM_DESCENDANTS cache in
   this case too.  This should be safe to do so now that we no longer
   substitute constraints on an auto.

gcc/cp/ChangeLog:

	* pt.cc (tsubst) <case TEMPLATE_TYPE_PARM>: Don't recurse when
	level lowering a cv-qualified type template parameter.  Remove
	recursive loop breaker in the level lowering case for constrained
	autos.  Use the TEMPLATE_PARM_DESCENDANTS cache in this case as
	well.
This commit is contained in:
Patrick Palka 2023-04-20 15:16:59 -04:00
parent 76fa66ea39
commit afc7e20e79

View file

@ -16228,33 +16228,24 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
/* If we get here, we must have been looking at a parm for a
more deeply nested template. Make a new version of this
template parameter, but with a lower level. */
int quals;
switch (code)
{
case TEMPLATE_TYPE_PARM:
case TEMPLATE_TEMPLATE_PARM:
if (cp_type_quals (t))
quals = cp_type_quals (t);
if (quals)
{
r = tsubst (TYPE_MAIN_VARIANT (t), args, complain, in_decl);
r = cp_build_qualified_type
(r, cp_type_quals (t),
complain | (code == TEMPLATE_TYPE_PARM
? tf_ignore_bad_quals : 0));
gcc_checking_assert (code == TEMPLATE_TYPE_PARM);
t = TYPE_MAIN_VARIANT (t);
}
else if (TREE_CODE (t) == TEMPLATE_TYPE_PARM
&& PLACEHOLDER_TYPE_CONSTRAINTS_INFO (t)
&& (r = (TEMPLATE_PARM_DESCENDANTS
(TEMPLATE_TYPE_PARM_INDEX (t))))
&& (r = TREE_TYPE (r))
&& !PLACEHOLDER_TYPE_CONSTRAINTS_INFO (r))
/* Break infinite recursion when substituting the constraints
of a constrained placeholder. */;
else if (TREE_CODE (t) == TEMPLATE_TYPE_PARM
&& !PLACEHOLDER_TYPE_CONSTRAINTS_INFO (t)
&& (arg = TEMPLATE_TYPE_PARM_INDEX (t),
r = TEMPLATE_PARM_DESCENDANTS (arg))
&& (TEMPLATE_PARM_LEVEL (r)
== TEMPLATE_PARM_LEVEL (arg) - levels))
/* Cache the simple case of lowering a type parameter. */
if (TREE_CODE (t) == TEMPLATE_TYPE_PARM
&& (arg = TEMPLATE_TYPE_PARM_INDEX (t),
r = TEMPLATE_PARM_DESCENDANTS (arg))
&& (TEMPLATE_PARM_LEVEL (r)
== TEMPLATE_PARM_LEVEL (arg) - levels))
/* Cache the simple case of lowering a type parameter. */
r = TREE_TYPE (r);
else
{
@ -16278,6 +16269,10 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
else
TYPE_CANONICAL (r) = canonical_type_parameter (r);
}
if (quals)
r = cp_build_qualified_type (r, quals,
complain | tf_ignore_bad_quals);
break;
case BOUND_TEMPLATE_TEMPLATE_PARM: