]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Mark implicit inline namespaces as purview [PR121724]
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 1 Sep 2025 11:28:03 +0000 (21:28 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 4 Sep 2025 07:46:20 +0000 (17:46 +1000)
When we push an existing namespace within the module purview for the
first time, we also need to mark any parent inline namespaces as purview
to not confuse the streaming logic.

PR c++/121724

gcc/cp/ChangeLog:

* name-lookup.cc (push_namespace): Mark inline namespace
contexts as purview if needed.

gcc/testsuite/ChangeLog:

* g++.dg/modules/namespace-12_a.C: New test.
* g++.dg/modules/namespace-12_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
(cherry picked from commit 03505e5b93e635907ed5ef7edac11da4026655e2)

gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/modules/namespace-12_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-12_b.C [new file with mode: 0644]

index d2898ec5d39545bc53ded967e12e9399e952be0f..72d480c56ae415466df58ab7ba84fe17fd0e943a 100644 (file)
@@ -9236,6 +9236,9 @@ push_namespace (tree name, bool make_inline)
                  gcc_checking_assert (!(tree)slot || (tree)slot == ctx);
                  slot = ctx;
                }
+
+             if (module_purview_p ())
+               DECL_MODULE_PURVIEW_P (ctx) = true;
            }
        }
 
diff --git a/gcc/testsuite/g++.dg/modules/namespace-12_a.C b/gcc/testsuite/g++.dg/modules/namespace-12_a.C
new file mode 100644 (file)
index 0000000..a432626
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/121724
+// { dg-additional-options "-fmodules -Wno-global-module" }
+// { dg-module-cmi foo }
+
+module;
+namespace A {
+  inline namespace X {
+    namespace B {
+    }
+  }
+}
+export module foo;
+export namespace A {
+  namespace B {
+    struct S {};
+  }
+}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-12_b.C b/gcc/testsuite/g++.dg/modules/namespace-12_b.C
new file mode 100644 (file)
index 0000000..8c429ba
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/121724
+// { dg-additional-options "-fmodules" }
+
+import foo;
+using T = A::B::S;
+using T = A::X::B::S;