From: Nathaniel Shead Date: Mon, 10 Nov 2025 12:41:25 +0000 (+1100) Subject: c++/modules: Propagate purviewness to all parent namespaces X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fbb6b2618e5220c049d889768b3aa3d48fda2ca;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 02e795fab33..bbbf49363e8 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 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 a; +export outer::inner::B b;