https://gcc.gnu.org/g:9813e49e95bc4bc2f0e030a7fdd0e7ef63c056fc

commit r16-6596-g9813e49e95bc4bc2f0e030a7fdd0e7ef63c056fc
Author: Nathaniel Shead <[email protected]>
Date:   Thu Jan 8 20:38:43 2026 +1100

    c++/modules: Mark implicit using-directive for imported unnamed namespace 
as imported [PR123393]
    
    The assertion failure in the PR is due to the implicit using-directive
    for the anonymous namespace not being considered imported, because
    make_namespace_finish calls add_using_namespace without propagating
    'from_import'.
    
            PR c++/123393
    
    gcc/cp/ChangeLog:
    
            * name-lookup.cc (make_namespace_finish): Pass from_import to
            add_using_namespace.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/namespace-18_a.C: New test.
            * g++.dg/modules/namespace-18_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <[email protected]>

Diff:
---
 gcc/cp/name-lookup.cc                         | 3 ++-
 gcc/testsuite/g++.dg/modules/namespace-18_a.C | 9 +++++++++
 gcc/testsuite/g++.dg/modules/namespace-18_b.C | 9 +++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index ff738f15d932..5d93c13265da 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -9288,7 +9288,8 @@ make_namespace_finish (tree ns, tree *slot, bool 
from_import = false)
   /* An unnamed namespace implicitly has a using-directive inserted so
      that its contents are usable in the surrounding context.  */
   if (!DECL_NAMESPACE_INLINE_P (ns) && !DECL_NAME (ns))
-    add_using_namespace (NAMESPACE_LEVEL (ctx)->using_directives, ns);
+    add_using_namespace (NAMESPACE_LEVEL (ctx)->using_directives, ns,
+                        from_import);
 }
 
 /* NS is a possibly-imported namespace that is now needed for
diff --git a/gcc/testsuite/g++.dg/modules/namespace-18_a.C 
b/gcc/testsuite/g++.dg/modules/namespace-18_a.C
new file mode 100644
index 000000000000..08a90285077b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-18_a.C
@@ -0,0 +1,9 @@
+// PR c++/123393
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi fmt }
+
+export module fmt;
+namespace fmt {
+  export template <typename T> void format(T);
+  namespace {}
+}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-18_b.C 
b/gcc/testsuite/g++.dg/modules/namespace-18_b.C
new file mode 100644
index 000000000000..4f6f70197424
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-18_b.C
@@ -0,0 +1,9 @@
+// PR c++123393
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi m }
+
+export module m;
+import fmt;
+inline void use() {
+  fmt::format("");
+}

Reply via email to