public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5606] c++: compare one level of template parms
@ 2023-11-20 2:54 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-11-20 2:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7
commit r14-5606-ge85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7
Author: Jason Merrill <jason@redhat.com>
Date: Fri Nov 17 17:17:32 2023 -0500
c++: compare one level of template parms
There should never be a reason to compare more than one level of template
parameters; additional levels are for the enclosing context, which is either
irrelevant (for a template template parameter) or already compared (for a
member template).
Also, the comp_template_parms handling of type parameters was wrongly
checking for TEMPLATE_TYPE_PARM when a type parameter appears here as a
TYPE_DECL.
gcc/cp/ChangeLog:
* pt.cc (comp_template_parms): Just one level.
(template_parameter_lists_equivalent_p): Likewise.
Diff:
---
gcc/cp/pt.cc | 94 ++++++++++++++++++++++--------------------------------------
1 file changed, 35 insertions(+), 59 deletions(-)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 1de9d3eb44f..ed681afb5d4 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -3274,53 +3274,40 @@ check_explicit_specialization (tree declarator,
int
comp_template_parms (const_tree parms1, const_tree parms2)
{
- const_tree p1;
- const_tree p2;
-
if (parms1 == parms2)
return 1;
- for (p1 = parms1, p2 = parms2;
- p1 != NULL_TREE && p2 != NULL_TREE;
- p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
+ tree t1 = TREE_VALUE (parms1);
+ tree t2 = TREE_VALUE (parms2);
+ int i;
+
+ gcc_assert (TREE_CODE (t1) == TREE_VEC);
+ gcc_assert (TREE_CODE (t2) == TREE_VEC);
+
+ if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
+ return 0;
+
+ for (i = 0; i < TREE_VEC_LENGTH (t2); ++i)
{
- tree t1 = TREE_VALUE (p1);
- tree t2 = TREE_VALUE (p2);
- int i;
+ tree parm1 = TREE_VALUE (TREE_VEC_ELT (t1, i));
+ tree parm2 = TREE_VALUE (TREE_VEC_ELT (t2, i));
- gcc_assert (TREE_CODE (t1) == TREE_VEC);
- gcc_assert (TREE_CODE (t2) == TREE_VEC);
+ /* If either of the template parameters are invalid, assume
+ they match for the sake of error recovery. */
+ if (error_operand_p (parm1) || error_operand_p (parm2))
+ return 1;
- if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
+ if (TREE_CODE (parm1) != TREE_CODE (parm2))
return 0;
- for (i = 0; i < TREE_VEC_LENGTH (t2); ++i)
- {
- tree parm1 = TREE_VALUE (TREE_VEC_ELT (t1, i));
- tree parm2 = TREE_VALUE (TREE_VEC_ELT (t2, i));
-
- /* If either of the template parameters are invalid, assume
- they match for the sake of error recovery. */
- if (error_operand_p (parm1) || error_operand_p (parm2))
- return 1;
-
- if (TREE_CODE (parm1) != TREE_CODE (parm2))
- return 0;
-
- if (TREE_CODE (parm1) == TEMPLATE_TYPE_PARM
- && (TEMPLATE_TYPE_PARAMETER_PACK (parm1)
- == TEMPLATE_TYPE_PARAMETER_PACK (parm2)))
- continue;
- else if (!same_type_p (TREE_TYPE (parm1), TREE_TYPE (parm2)))
- return 0;
- }
+ if (TREE_CODE (parm1) == TYPE_DECL
+ && (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm1))
+ == TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm2))))
+ continue;
+ else if (!same_type_p (TREE_TYPE (parm1), TREE_TYPE (parm2)))
+ return 0;
}
- if ((p1 != NULL_TREE) != (p2 != NULL_TREE))
- /* One set of parameters has more parameters lists than the
- other. */
- return 0;
-
return 1;
}
@@ -3403,31 +3390,20 @@ template_parameter_lists_equivalent_p (const_tree parms1, const_tree parms2)
if (parms1 == parms2)
return true;
- const_tree p1 = parms1;
- const_tree p2 = parms2;
- while (p1 != NULL_TREE && p2 != NULL_TREE)
+ tree list1 = TREE_VALUE (parms1);
+ tree list2 = TREE_VALUE (parms2);
+
+ if (TREE_VEC_LENGTH (list1) != TREE_VEC_LENGTH (list2))
+ return 0;
+
+ for (int i = 0; i < TREE_VEC_LENGTH (list2); ++i)
{
- tree list1 = TREE_VALUE (p1);
- tree list2 = TREE_VALUE (p2);
-
- if (TREE_VEC_LENGTH (list1) != TREE_VEC_LENGTH (list2))
- return 0;
-
- for (int i = 0; i < TREE_VEC_LENGTH (list2); ++i)
- {
- tree parm1 = TREE_VEC_ELT (list1, i);
- tree parm2 = TREE_VEC_ELT (list2, i);
- if (!template_parameters_equivalent_p (parm1, parm2))
- return false;
- }
-
- p1 = TREE_CHAIN (p1);
- p2 = TREE_CHAIN (p2);
+ tree parm1 = TREE_VEC_ELT (list1, i);
+ tree parm2 = TREE_VEC_ELT (list2, i);
+ if (!template_parameters_equivalent_p (parm1, parm2))
+ return false;
}
- if ((p1 != NULL_TREE) != (p2 != NULL_TREE))
- return false;
-
return true;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-20 2:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-20 2:54 [gcc r14-5606] c++: compare one level of template parms Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).