re PR c++/17232 ([DR 1640] classes and class template specializations treated differe...
[gcc.git] / gcc / cp / pt.c
index 427447913ecfb9cc7a0c1ad58913a2ffbd40e580..531d8607aff393b0ac5eb46f3e09c030067edec6 100644 (file)
@@ -10285,7 +10285,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
            DECL_TEMPLATE_INFO (r)
              = build_template_info (gen_tmpl, argvec);
            SET_DECL_IMPLICIT_INSTANTIATION (r);
-           register_specialization (r, gen_tmpl, argvec, false, hash);
+
+           tree new_r
+             = register_specialization (r, gen_tmpl, argvec, false, hash);
+           if (new_r != r)
+             /* We instantiated this while substituting into
+                the type earlier (template/friend54.C).  */
+             RETURN (new_r);
 
            /* We're not supposed to instantiate default arguments
               until they are called, for a template.  But, for a