Bootstrapped and regtested (so far just modules.exp) on
x86_64-pc-linux-gnu, OK for trunk if full regtest succeeds?
-- >8 --
The issue in the PR is that we're checking if the binding entity for the
current TU matches the namespace we're pushing. In this case the slot
however is a STAT_HACK we created during 'maybe_record_mergeable_decl'
to indicate that the binding entity contains a global module binding.
Adding '|| (STAT_HACK_P ((tree) slot) && STAT_DECL ((tree) slot) == ns)'
should fix the assertion, but I think we want to just not build the
STAT_HACK for namespaces, as they'll always be global module regardless,
and cannot match with any other declaration, so there's no need for the
special flag.
PR c++/122995
gcc/cp/ChangeLog:
* name-lookup.cc (maybe_record_mergeable_decl): Don't build a
STAT_HACK for namespaces.
gcc/testsuite/ChangeLog:
* g++.dg/modules/namespace-17_a.C: New test.
* g++.dg/modules/namespace-17_b.C: New test.
Signed-off-by: Nathaniel Shead <[email protected]>
---
gcc/cp/name-lookup.cc | 4 +++-
gcc/testsuite/g++.dg/modules/namespace-17_a.C | 8 ++++++++
gcc/testsuite/g++.dg/modules/namespace-17_b.C | 10 ++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/modules/namespace-17_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/namespace-17_b.C
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 4c07fd40f64..8fa5a0c246d 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -3791,7 +3791,9 @@ maybe_record_mergeable_decl (tree *slot, tree name, tree
decl)
(slot, name, is_attached ? BINDING_SLOT_PARTITION : BINDING_SLOT_GLOBAL,
true);
- if (!is_attached)
+ /* A namespace is always global module so there's no need to mark
+ the current binding slot as such. */
+ if (!is_attached && TREE_CODE (decl) != NAMESPACE_DECL)
{
binding_slot &orig
= BINDING_VECTOR_CLUSTER (*slot, 0).slots[BINDING_SLOT_CURRENT];
diff --git a/gcc/testsuite/g++.dg/modules/namespace-17_a.C
b/gcc/testsuite/g++.dg/modules/namespace-17_a.C
new file mode 100644
index 00000000000..e78a8245cad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-17_a.C
@@ -0,0 +1,8 @@
+// PR c++/122995
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi bug2 }
+
+export module bug2;
+namespace N {
+ namespace C { struct r3_cpo; } export extern inline C::r3_cpo const r3;
+}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-17_b.C
b/gcc/testsuite/g++.dg/modules/namespace-17_b.C
new file mode 100644
index 00000000000..33d56db0819
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/namespace-17_b.C
@@ -0,0 +1,10 @@
+// PR c++/122995
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi bug }
+
+export module bug;
+import bug2;
+namespace N {
+ namespace C { struct r1_cpo; } export extern inline C::r1_cpo const r1;
+ namespace C { struct r2_cpo; } export extern inline C::r2_cpo const r2;
+}
--
2.51.0