]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Propagate purviewness to all parent namespaces
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 10 Nov 2025 12:41:25 +0000 (23:41 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Mon, 10 Nov 2025 22:13:09 +0000 (09:13 +1100)
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 <nathanieloshead@gmail.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/tpl-friend-8_a.H
gcc/testsuite/g++.dg/modules/tpl-friend-8_b.C

index 02e795fab33ff8733412d3c73148e7259bebaf55..bbbf49363e8f01ffc7fe5b7836a72c741649c36a 100644 (file)
@@ -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
     {
index bd2290460b5a3cbe1da0605ee78dbe6ed66a2505..7269d8eb7946901214586bbdff7fbb89ea03961a 100644 (file)
@@ -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() {}
+      };
+    }
+  }
+}
index 76d7447c2ebcb14fa9b517f70e30f45667b1414d..47569aa83c52700ab27ae8269a25f2a539e16d6c 100644 (file)
@@ -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;