diff options
author | Patrick Palka <ppalka@redhat.com> | 2023-04-20 15:16:59 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2023-04-20 15:16:59 -0400 |
commit | afc7e20e793ce4071a7fe593ccebb2e6b2b070fa (patch) | |
tree | 432fccaeea5eba1244395651403b43769b724448 | |
parent | 76fa66ea397cb255ab1d68a90ff6b878236e9620 (diff) | |
download | gcc-afc7e20e793ce4071a7fe593ccebb2e6b2b070fa.zip gcc-afc7e20e793ce4071a7fe593ccebb2e6b2b070fa.tar.gz gcc-afc7e20e793ce4071a7fe593ccebb2e6b2b070fa.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/pt.cc | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index d393c99..3e5f010 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -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: |