https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116364

--- Comment #1 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
The following (untested) patch seems to fix the issue:

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index f4d137b13a1..75967c259fc 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -13521,11 +13521,16 @@ depset::hash::add_specializations (bool decl_p)
         }

       bool needs_reaching = false;
-      if (use_tpl == 1)
+      tree not_tmpl = STRIP_TEMPLATE (spec);
+      if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_IMPORT_P (not_tmpl))
+        /* If we've imported the specialisation then something probably
+           needed it, so consider it reachable.  If it's not from a
+           partition then we won't emit it anyway.  */;
+      else if (use_tpl == 1)
         /* Implicit instantiations only walked if we reach them.  */
         needs_reaching = true;
-      else if (!DECL_LANG_SPECIFIC (STRIP_TEMPLATE (spec))
-               || !DECL_MODULE_PURVIEW_P (STRIP_TEMPLATE (spec)))
+      else if (!DECL_LANG_SPECIFIC (not_tmpl)
+               || !DECL_MODULE_PURVIEW_P (not_tmpl))
         /* Likewise, GMF explicit or partial specializations.  */
         needs_reaching = true;

Reply via email to