Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
A missed case in r17-4959: we were clearing DECL_INITIAL for a redefined
specialization, leading to confusion later on.
PR c++/127787
PR c++/99000
gcc/cp/ChangeLog:
* pt.cc (check_explicit_specialization): Don't clobber a redefinable
imported definition.
gcc/testsuite/ChangeLog:
* g++.dg/modules/gmf-8.h: New test.
* g++.dg/modules/gmf-8_a.C: New test.
* g++.dg/modules/gmf-8_b.C: New test.
---
gcc/testsuite/g++.dg/modules/gmf-8.h | 4 ++++
gcc/cp/pt.cc | 3 +++
gcc/testsuite/g++.dg/modules/gmf-8_a.C | 7 +++++++
gcc/testsuite/g++.dg/modules/gmf-8_b.C | 3 +++
4 files changed, 17 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/modules/gmf-8.h
create mode 100644 gcc/testsuite/g++.dg/modules/gmf-8_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/gmf-8_b.C
diff --git a/gcc/testsuite/g++.dg/modules/gmf-8.h
b/gcc/testsuite/g++.dg/modules/gmf-8.h
new file mode 100644
index 00000000000..2058752601b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gmf-8.h
@@ -0,0 +1,4 @@
+namespace N {
+template<class T> struct A { template<class U> void f(); };
+template<> template<class U> void A<int>::f() { }
+}
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 945554663a2..f46916a256d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -3377,6 +3377,9 @@ check_explicit_specialization (tree declarator,
if (tsk == tsk_template && !was_template_id)
{
tree result = DECL_TEMPLATE_RESULT (tmpl);
+ if (DECL_TEMPLATE_SPECIALIZATION (tmpl)
+ && redefinable_import_p (tmpl))
+ return tmpl;
SET_DECL_TEMPLATE_SPECIALIZATION (tmpl);
DECL_INITIAL (result) = NULL_TREE;
if (have_def)
diff --git a/gcc/testsuite/g++.dg/modules/gmf-8_a.C
b/gcc/testsuite/g++.dg/modules/gmf-8_a.C
new file mode 100644
index 00000000000..ab037c0cd4e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gmf-8_a.C
@@ -0,0 +1,7 @@
+// PR c++/127787
+// { dg-additional-options -fmodules }
+
+module;
+#include "gmf-8.h"
+export module M;
+export using N::A;
diff --git a/gcc/testsuite/g++.dg/modules/gmf-8_b.C
b/gcc/testsuite/g++.dg/modules/gmf-8_b.C
new file mode 100644
index 00000000000..6a6ab626620
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gmf-8_b.C
@@ -0,0 +1,3 @@
+// { dg-additional-options -fmodules }
+import M;
+#include "gmf-8.h"
base-commit: 1152c67150f4051d1a44ed52e8aafe3c9bbe4eb9
--
2.56.0