[gcc/devel/ranger] c++: tpl-tpl-parms are not canonicalizable types [pr94454]

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 20:33:34 GMT 2020


https://gcc.gnu.org/g:a6f400239d792ddcff106be22b04fdf3f9b2894a

commit a6f400239d792ddcff106be22b04fdf3f9b2894a
Author: Nathan Sidwell <nathan@acm.org>
Date:   Mon Apr 20 06:52:30 2020 -0700

    c++: tpl-tpl-parms are not canonicalizable types [pr94454]
    
    We treat tpl-tpl-parms as types.  They're not; bound-tpl-tpl-parms
    are.  We can get away with them being type-like.  Unfortunately we
    give the original level==orig_level case a canonical type, but the
    reduced cases of level<orig_level get structural equality.  This patch
    gives them structural type always.
    
            * pt.c (canonical_type_parameter): Assert not a tpl-tpl-parm.
            (process_template_parm): tpl-tpl-parms are structural.
            (rewrite_template_parm): Propagate structuralness.

Diff:
---
 gcc/cp/ChangeLog |  5 +++++
 gcc/cp/pt.c      | 13 +++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 49db85d1c1a..e210eb5b80e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
 2020-04-20  Nathan Sidwell  <nathan@acm.org>
 
+	PR 94454 - tpl-tpl-parms are not canonicalizable types
+	* pt.c (canonical_type_parameter): Assert not a tpl-tpl-parm.
+	(process_template_parm): tpl-tpl-parms are structural.
+	(rewrite_template_parm): Propagate structuralness.
+
 	PR 94454 - Expr pack expansion equality
 	* tree.c (cp_tree_equal): [TEMPLATE_ID_EXPR, default] Refactor.
 	[EXPR_PACK_EXPANSION]: Add.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4814b768c2c..4f4c04e7df8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4399,6 +4399,9 @@ canonical_type_parameter (tree type)
 {
   tree list;
   int idx = TEMPLATE_TYPE_IDX (type);
+
+  gcc_assert (TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM);
+
   if (!canonical_template_parms)
     vec_alloc (canonical_template_parms, idx + 1);
 
@@ -4581,7 +4584,10 @@ process_template_parm (tree list, location_t parm_loc, tree parm,
 				     processing_template_decl,
 				     decl, TREE_TYPE (parm));
       TEMPLATE_TYPE_PARAMETER_PACK (t) = is_parameter_pack;
-      TYPE_CANONICAL (t) = canonical_type_parameter (t);
+      if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
+	SET_TYPE_STRUCTURAL_EQUALITY (t);
+      else
+	TYPE_CANONICAL (t) = canonical_type_parameter (t);
     }
   DECL_ARTIFICIAL (decl) = 1;
   SET_DECL_TEMPLATE_PARM_P (decl);
@@ -28022,7 +28028,10 @@ rewrite_template_parm (tree olddecl, unsigned index, unsigned level,
       TEMPLATE_PARM_PARAMETER_PACK (newidx)
 	= TEMPLATE_PARM_PARAMETER_PACK (oldidx);
       TYPE_STUB_DECL (newtype) = TYPE_NAME (newtype) = newdecl;
-      TYPE_CANONICAL (newtype) = canonical_type_parameter (newtype);
+      if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (olddecl)))
+	SET_TYPE_STRUCTURAL_EQUALITY (newtype);
+      else
+	TYPE_CANONICAL (newtype) = canonical_type_parameter (newtype);
 
       if (TREE_CODE (olddecl) == TEMPLATE_DECL)
 	{


More information about the Gcc-cvs mailing list