diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 0141c53b617c87e7ac3afac1fa7e7a5bfca1a474..b590c32345f6e6ba2d6b6fd8cdcb6ed58400d846 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -1546,9 +1546,7 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend,
   elt.tmpl = tmpl;
   elt.args = args;
   elt.spec = spec;
-
-  if (hash == 0)
-    hash = spec_hasher::hash (&elt);
+  elt.hash = hash;
 
   spec_entry **slot = decl_specializations->find_slot (&elt, INSERT);
   if (*slot)