@@ -13723,15 +13723,15 @@ depset::hash::add_binding_entity (tree decl, WMB_Flags flags, void *data_)
return (flags & WMB_Using
? flags & WMB_Export : DECL_MODULE_EXPORT_P (decl));
}
- else if (DECL_NAME (decl) && !data->met_namespace)
+ else if (!data->met_namespace)
{
/* Namespace, walk exactly once. */
- gcc_checking_assert (TREE_PUBLIC (decl));
data->met_namespace = true;
if (data->hash->add_namespace_entities (decl, data->partitions))
{
/* It contains an exported thing, so it is exported. */
gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl));
+ gcc_checking_assert (TREE_PUBLIC (decl) || header_module_p ());
DECL_MODULE_EXPORT_P (decl) = true;
}
@@ -16126,8 +16126,7 @@ module_state::write_namespaces (elf_out *to, vec<depset *> spaces,
tree ns = b->get_entity ();
gcc_checking_assert (TREE_CODE (ns) == NAMESPACE_DECL);
- /* P1815 may have something to say about this. */
- gcc_checking_assert (TREE_PUBLIC (ns));
+ gcc_checking_assert (TREE_PUBLIC (ns) || header_module_p ());
unsigned flags = 0;
if (TREE_PUBLIC (ns))
@@ -9102,6 +9102,11 @@ make_namespace_finish (tree ns, tree *slot, bool from_import = false)
if (DECL_NAMESPACE_INLINE_P (ns) || !DECL_NAME (ns))
emit_debug_info_using_namespace (ctx, ns, true);
+
+ /* 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);
}
/* Push into the scope of the NAME namespace. If NAME is NULL_TREE,
@@ -9238,11 +9243,6 @@ push_namespace (tree name, bool make_inline)
gcc_checking_assert (slot);
}
make_namespace_finish (ns, slot);
-
- /* Add the anon using-directive here, we don't do it in
- make_namespace_finish. */
- if (!DECL_NAMESPACE_INLINE_P (ns) && !name)
- add_using_namespace (current_binding_level->using_directives, ns);
}
}
new file mode 100644
@@ -0,0 +1,28 @@
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+static int x = 123;
+static void f() {}
+template <typename T> static void t() {}
+
+namespace {
+ int y = 456;
+ void g() {};
+ template <typename T> void u() {}
+
+ namespace ns { int in_ns = 456; }
+
+ struct A {};
+ template <typename T> struct B {};
+
+ enum E { X };
+ enum class F { Y };
+
+ template <typename T> using U = int;
+
+#if __cplusplus >= 202002L
+ template <typename T> concept C = true;
+#endif
+}
+
+namespace ns2 = ns;
new file mode 100644
@@ -0,0 +1,29 @@
+// { dg-additional-options "-fmodules-ts" }
+
+import "internal-9_a.H";
+
+int main() {
+ auto x2 = x;
+ f();
+ t<int>();
+
+ auto y2 = y;
+ g();
+ u<int>();
+
+ int val1 = ns::in_ns;
+
+ A a;
+ B<int> b;
+
+ E e = X;
+ F f = F::Y;
+
+ U<int> temp;
+
+#if __cplusplus >= 202002L
+ static_assert(C<int>);
+#endif
+
+ int val2 = ns2::in_ns;
+}