https://gcc.gnu.org/g:e1cf6f306d9b6e449c0ba9b3da314dc2f6220a84

commit r17-5096-ge1cf6f306d9b6e449c0ba9b3da314dc2f6220a84
Author: Jason Merrill <[email protected]>
Date:   Mon Oct 12 12:20:20 2026 -0400

    c++/modules: P1811 and member specialization [PR127787]
    
    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.

Diff:
---
 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(+)

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 000000000000..2058752601b0
--- /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 945554663a2c..f46916a256d1 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 000000000000..ab037c0cd4e2
--- /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 000000000000..6a6ab626620e
--- /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"

Reply via email to