Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
Here since r16-4484 we include all namespaces in the current purview in a
module, even if the namespace comes from another partition. That breaks for
an anonymous namespace, which is local to the TU (and added to the
definition of TU-local entity by P2996 Reflection); here _c ended up
representing the anonymous namespace from _a separately from the same one
passed along from _b, leading to an ICE trying to import them into the same
slot in _d. I tried just adding namespaces to is_tu_local_entity, but that
broke other things, so for 16.2 let's handle them here.
PR c++/126209
gcc/cp/ChangeLog:
* module.cc (depset::hash::add_namespace_entities): Don't
force out anonymous namespaces.
gcc/testsuite/ChangeLog:
* g++.dg/modules/anon-5_a.C: New test.
* g++.dg/modules/anon-5_b.C: New test.
* g++.dg/modules/anon-5_c.C: New test.
* g++.dg/modules/anon-5_d.C: New test.
---
gcc/cp/module.cc | 6 ++++++
gcc/testsuite/g++.dg/modules/anon-5_a.C | 6 ++++++
gcc/testsuite/g++.dg/modules/anon-5_b.C | 3 +++
gcc/testsuite/g++.dg/modules/anon-5_c.C | 4 ++++
gcc/testsuite/g++.dg/modules/anon-5_d.C | 3 +++
5 files changed, 22 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/modules/anon-5_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/anon-5_b.C
create mode 100644 gcc/testsuite/g++.dg/modules/anon-5_c.C
create mode 100644 gcc/testsuite/g++.dg/modules/anon-5_d.C
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index f7569e688a2..49a47494467 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -15202,6 +15202,12 @@ depset::hash::add_namespace_entities (tree ns, bitmap
partitions)
for (tree udir : NAMESPACE_LEVEL (ns)->using_directives)
if (TREE_CODE (udir) == USING_DECL && DECL_MODULE_PURVIEW_P (udir))
{
+ /* Unless it's a (TU-local) anonymous namespace.
+
+ FIXME instead of checking here, they should be
+ is_tu_local_entity. */
+ if (!TREE_PUBLIC (USING_DECL_DECLS (udir)))
+ continue;
make_dependency (USING_DECL_DECLS (udir), depset::EK_NAMESPACE);
if (DECL_MODULE_EXPORT_P (udir))
count++;
diff --git a/gcc/testsuite/g++.dg/modules/anon-5_a.C
b/gcc/testsuite/g++.dg/modules/anon-5_a.C
new file mode 100644
index 00000000000..6cc266b5c04
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/anon-5_a.C
@@ -0,0 +1,6 @@
+// PR c++/126209
+// { dg-additional-options -fmodules }
+// { dg-module-cmi }
+export module kernel:event;
+namespace { int anchor = 0; }
+inline int i = anchor;
diff --git a/gcc/testsuite/g++.dg/modules/anon-5_b.C
b/gcc/testsuite/g++.dg/modules/anon-5_b.C
new file mode 100644
index 00000000000..9f75fd3e900
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/anon-5_b.C
@@ -0,0 +1,3 @@
+// { dg-additional-options -fmodules }
+export module kernel:memories;
+import :event;
diff --git a/gcc/testsuite/g++.dg/modules/anon-5_c.C
b/gcc/testsuite/g++.dg/modules/anon-5_c.C
new file mode 100644
index 00000000000..bf66276d7d6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/anon-5_c.C
@@ -0,0 +1,4 @@
+// { dg-additional-options -fmodules }
+export module kernel;
+export import :event;
+export import :memories;
diff --git a/gcc/testsuite/g++.dg/modules/anon-5_d.C
b/gcc/testsuite/g++.dg/modules/anon-5_d.C
new file mode 100644
index 00000000000..002c54da54d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/anon-5_d.C
@@ -0,0 +1,3 @@
+// { dg-additional-options -fmodules }
+import kernel;
+int main() { return 0; }
base-commit: d2d281c2f81b58fb7298da4c40c4e8434c097b71
--
2.55.0