I discovered that while regular TPIs are pointed to by their owning decl, reduced TPIs were not. This caused me problems on the modules branch and seems like a needless inconsistency. While there I did a small amount of cleanup.

I also noticed that convert_generic_types_to_packs was passing the original type into reduce_template_parm_level, rather than the copied type. This just seems wrong, and with the above change would become (more?) broken. Every other call to RTPL passes in the copied type.

Applying to trunk.

nathan

--
Nathan Sidwell
2019-10-24  Nathan Sidwell  <nat...@acm.org>

	* pt.c (reduce_template_parm_level): Attach the new TPI to the new
	DECL.
	(convert_generic_types_to_packs): Pass the copied type to
	reduce_templatE_parm_level.

Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 277405)
+++ gcc/cp/pt.c	(working copy)
@@ -4430,8 +4430,8 @@ reduce_template_parm_level (tree index,
     {
       tree orig_decl = TEMPLATE_PARM_DECL (index);
-      tree decl, t;
 
-      decl = build_decl (DECL_SOURCE_LOCATION (orig_decl),
-			 TREE_CODE (orig_decl), DECL_NAME (orig_decl), type);
+      tree decl = build_decl (DECL_SOURCE_LOCATION (orig_decl),
+			      TREE_CODE (orig_decl), DECL_NAME (orig_decl),
+			      type);
       TREE_CONSTANT (decl) = TREE_CONSTANT (orig_decl);
       TREE_READONLY (decl) = TREE_READONLY (orig_decl);
@@ -4439,22 +4439,29 @@ reduce_template_parm_level (tree index,
       SET_DECL_TEMPLATE_PARM_P (decl);
 
-      t = build_template_parm_index (TEMPLATE_PARM_IDX (index),
-				     TEMPLATE_PARM_LEVEL (index) - levels,
-				     TEMPLATE_PARM_ORIG_LEVEL (index),
-				     decl, type);
-      TEMPLATE_PARM_DESCENDANTS (index) = t;
-      TEMPLATE_PARM_PARAMETER_PACK (t)
+      tree tpi = build_template_parm_index (TEMPLATE_PARM_IDX (index),
+					    TEMPLATE_PARM_LEVEL (index) - levels,
+					    TEMPLATE_PARM_ORIG_LEVEL (index),
+					    decl, type);
+      TEMPLATE_PARM_DESCENDANTS (index) = tpi;
+      TEMPLATE_PARM_PARAMETER_PACK (tpi)
 	= TEMPLATE_PARM_PARAMETER_PACK (index);
 
 	/* Template template parameters need this.  */
+      tree inner = decl;
       if (TREE_CODE (decl) == TEMPLATE_DECL)
 	{
-	  DECL_TEMPLATE_RESULT (decl)
-	    = build_decl (DECL_SOURCE_LOCATION (decl),
-			  TYPE_DECL, DECL_NAME (decl), type);
-	  DECL_ARTIFICIAL (DECL_TEMPLATE_RESULT (decl)) = true;
+	  inner = build_decl (DECL_SOURCE_LOCATION (decl),
+			      TYPE_DECL, DECL_NAME (decl), type);
+	  DECL_TEMPLATE_RESULT (decl) = inner;
+	  DECL_ARTIFICIAL (inner) = true;
 	  DECL_TEMPLATE_PARMS (decl) = tsubst_template_parms
 	    (DECL_TEMPLATE_PARMS (orig_decl), args, complain);
 	}
+
+      /* Attach the TPI to the decl.  */
+      if (TREE_CODE (inner) == TYPE_DECL)
+	TEMPLATE_TYPE_PARM_INDEX (type) = tpi;
+      else
+	DECL_INITIAL (decl) = tpi;
     }
 
@@ -28441,5 +28448,5 @@ convert_generic_types_to_packs (tree par
       TEMPLATE_TYPE_PARM_INDEX (t)
 	= reduce_template_parm_level (TEMPLATE_TYPE_PARM_INDEX (o),
-				      o, 0, 0, tf_none);
+				      t, 0, 0, tf_none);
       TREE_TYPE (TEMPLATE_TYPE_DECL (t)) = t;
       TYPE_STUB_DECL (t) = TYPE_NAME (t) = TEMPLATE_TYPE_DECL (t);

Reply via email to