diff mbox series

[c++] alias template instantiation

Message ID 873e0eff-aa87-f555-f1d6-3346a699e436@acm.org
State New
Headers show
Series [c++] alias template instantiation | expand

Commit Message

Nathan Sidwell May 19, 2020, 8:33 p.m. UTC
Here's a small cleanup discovered by modules.  The alias instantiation 
machinery would setup template_info, and then sometime later overwrite 
that with equivalent info.  The template info, once set, is logically 
immutable.  Let's just not do that.

pushed to master

nathan
diff mbox series

Patch

2020-05-19  Nathan Sidwell  <nathan@acm.org>

	* pt.c (lookup_template_class_1): Do not reinit template_info of an
	alias here.

diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c
index 4d9651acee6..c17a038c6d0 100644
--- i/gcc/cp/pt.c
+++ w/gcc/cp/pt.c
@@ -10062,8 +10062,21 @@  lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
 	    }
 	}
 
-      // Build template info for the new specialization.
-      SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist));
+      /* Build template info for the new specialization.  This can
+	 overwrite the existing TEMPLATE_INFO for T (that points to
+	 its instantiated TEMPLATE_DECL), with this one that points to
+	 the most general template, but that's what we want.  */
+
+      if (TYPE_ALIAS_P (t))
+	{
+	  /* This should already have been constructed during
+	     instantiation of the alias decl.  */
+	  tree ti = DECL_TEMPLATE_INFO (TYPE_NAME (t));
+	  gcc_checking_assert (template_args_equal (TI_ARGS (ti), arglist)
+			       && TI_TEMPLATE (ti) == found);
+	}
+      else
+	SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist));
 
       elt.spec = t;
       slot = type_specializations->find_slot_with_hash (&elt, hash, INSERT);