]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Mark implicit using-directive for imported unnamed namespace as imported...
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 8 Jan 2026 09:38:43 +0000 (20:38 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 9 Jan 2026 10:37:56 +0000 (21:37 +1100)
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 <nathanieloshead@gmail.com>
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/modules/namespace-18_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-18_b.C [new file with mode: 0644]

index ff738f15d932a8f8c2d6564c17c4234b11e0703e..5d93c13265da022bea954962b029dd7d05ed1fac 100644 (file)
@@ -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 (file)
index 0000000..08a9028
--- /dev/null
@@ -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 (file)
index 0000000..4f6f701
--- /dev/null
@@ -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("");
+}