https://gcc.gnu.org/g:2fbb6b2618e5220c049d889768b3aa3d48fda2ca
commit r16-5142-g2fbb6b2618e5220c049d889768b3aa3d48fda2ca Author: Nathaniel Shead <[email protected]> Date: Mon Nov 10 23:41:25 2025 +1100 c++/modules: Propagate purviewness to all parent namespaces 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]> Diff: --- 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 02e795fab33f..bbbf49363e8f 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 bd2290460b5a..7269d8eb7946 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 76d7447c2ebc..47569aa83c52 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;
