On 11/10/25 6:14 PM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

OK.
-- >8 --

In PR c++/100134, tsubst_friend_function was adjusted to ensure that
instantiating a friend function in an unopened namespace still correctly
marked the namespace as purview.  This adjusts the fix to also apply
to nested namespaces.

gcc/cp/ChangeLog:

        * pt.cc (tsubst_friend_function): Mark all parent namespaces as
        purview if needed.

gcc/testsuite/ChangeLog:

        * g++.dg/modules/tpl-friend-8_a.H: Add testcase.
        * g++.dg/modules/tpl-friend-8_b.C: Add testcase.

Signed-off-by: Nathaniel Shead <[email protected]>
---
  gcc/cp/pt.cc                                  |  7 ++++---
  gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H | 10 ++++++++++
  gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C |  7 ++++++-
  3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c233bb95cad..a084cd11da0 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11905,9 +11905,10 @@ tsubst_friend_function (tree decl, tree args)
         without necessarily having opened the enclosing namespace, so
         make sure the namespace is in the purview now too.  */
        if (modules_p ()
-         && DECL_MODULE_PURVIEW_P (STRIP_TEMPLATE (new_friend))
-         && TREE_CODE (DECL_CONTEXT (new_friend)) == NAMESPACE_DECL)
-       DECL_MODULE_PURVIEW_P (DECL_CONTEXT (new_friend)) = true;
+         && DECL_MODULE_PURVIEW_P (STRIP_TEMPLATE (new_friend)))
+       for (tree ctx = DECL_CONTEXT (new_friend);
+            TREE_CODE (ctx) == NAMESPACE_DECL; ctx = DECL_CONTEXT (ctx))
+         DECL_MODULE_PURVIEW_P (ctx) = true;
      }
    else
      {
diff --git a/gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H 
b/gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H
index bd2290460b5..7269d8eb794 100644
--- a/gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H
+++ b/gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H
@@ -7,3 +7,13 @@ namespace std {
      friend void f(A) { }
    };
  }
+
+namespace outer {
+  namespace inner {
+    inline namespace more_inner {
+      template<class T> struct B {
+       friend void g() {}
+      };
+    }
+  }
+}
diff --git a/gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C 
b/gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C
index 76d7447c2eb..47569aa83c5 100644
--- a/gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C
+++ b/gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C
@@ -1,8 +1,13 @@
  // PR c++/100134
-// { dg-additional-options -fmodules-ts }
+// { dg-additional-options "-fmodules -Wno-global-module" }
  // { dg-module-cmi pr100134 }
+module;
+namespace outer::inner {
+  inline namespace more_inner {}
+}
  export module pr100134;
import "tpl-friend-8_a.H"; export std::A<int> a;
+export outer::inner::B<int> b;

Reply via email to