In tracking a surprise on the modules branch, I came across this code in duplicate decls. Why would the newly minted decl already have specializations? That smells wrong.

This chainon call was added by Mark Mitchell back in 1998, (rev 21876) to deal with template friends of templates. Since that time we've cleaned a lot of that code up, and in particular do not push the friend template until instantiation time. I believe these changes make this chainon unneeded.

This patch changes it to assert there aren't any such specializations to concatenate. I'm putting this on trunk to give it wider exposure than I can on the modules branch. It has survived bootstrap on x86_64-linux.

nathan

--
Nathan Sidwell
2019-05-28  Nathan Sidwell  <nat...@acm.org>

	* decl.c (duplicate_decls): Assert a template newdecl has no
	specializations.

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 271712)
+++ cp/decl.c	(working copy)
@@ -2026,7 +2026,8 @@ duplicate_decls (tree newdecl, tree oldd
       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
-      DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
-	= chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
-		   DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
+
+      /* The new decl should not already have gathered any
+	 specializations.  */
+      gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
 
       DECL_ATTRIBUTES (old_result)

Reply via email to