On 9/1/25 7:31 AM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk and 15?

OK.

-- >8 --

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 <nathanielosh...@gmail.com>
---
  gcc/cp/name-lookup.cc                         |  3 +++
  gcc/testsuite/g++.dg/modules/namespace-12_a.C | 17 +++++++++++++++++
  gcc/testsuite/g++.dg/modules/namespace-12_b.C |  6 ++++++
  3 files changed, 26 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/modules/namespace-12_a.C
  create mode 100644 gcc/testsuite/g++.dg/modules/namespace-12_b.C

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index ba624677625..f5e80503678 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -9273,6 +9273,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
index 00000000000..a43262638f1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-12_a.C
@@ -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
index 00000000000..8c429ba9e73
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-12_b.C
@@ -0,0 +1,6 @@
+// PR c++/121724
+// { dg-additional-options "-fmodules" }
+
+import foo;
+using T = A::B::S;
+using T = A::X::B::S;

Reply via email to