bool exported = DECL_MODULE_EXPORT_P (udir);
tree target = USING_DECL_DECLS (udir);
depset *target_dep = table.find_dependency (target);
- gcc_checking_assert (target_dep);
+
+ /* An using-directive imported from a different module might not
+ have been walked earlier (PR c++/122915). But importers will
+ be able to just refer to the decl in that module unless it was
+ a partition anyway, so we don't have anything to do here. */
+ if (!target_dep || target_dep->is_import ())
+ {
+ gcc_checking_assert (DECL_MODULE_IMPORT_P (udir));
+ continue;
+ }
dump () && dump ("Writing using-directive in %N for %N",
parent, target);
dump () && dump ("Read using-directive in %N for %N", parent, target);
if (exported || is_module () || is_partition ())
- add_using_namespace (parent, target);
+ add_imported_using_namespace (parent, target);
}
dump.outdent ();
unqualified search. */
static void
-add_using_namespace (vec<tree, va_gc> *&usings, tree target)
+add_using_namespace (vec<tree, va_gc> *&usings, tree target,
+ bool imported = false)
{
/* Find if this using already exists. */
tree old = NULL_TREE;
{
decl = build_lang_decl (USING_DECL, NULL_TREE, NULL_TREE);
USING_DECL_DECLS (decl) = target;
+ DECL_MODULE_IMPORT_P (decl) = imported;
}
- /* Update purviewness and exportedness in case that has changed. */
+ /* Update module flags in case that has changed. */
if (modules_p ())
{
if (module_purview_p ())
DECL_MODULE_PURVIEW_P (decl) = true;
if (module_exporting_p ())
DECL_MODULE_EXPORT_P (decl) = true;
+ if (!imported)
+ DECL_MODULE_IMPORT_P (decl) = false;
}
if (!old)
}
/* Convenience overload for the above, taking the user as its first
- parameter. */
+ parameter, for use when importing a using-directive. */
void
-add_using_namespace (tree ns, tree target)
+add_imported_using_namespace (tree ns, tree target)
{
add_using_namespace (NAMESPACE_LEVEL (ns)->using_directives,
- ORIGINAL_NAMESPACE (target));
+ ORIGINAL_NAMESPACE (target),
+ /*imported=*/true);
}
/* Tell the debug system of a using directive. */
extern void cp_emit_debug_info_for_using (tree, tree);
extern void finish_nonmember_using_decl (tree scope, tree name);
-extern void add_using_namespace (tree, tree);
extern void finish_using_directive (tree target, tree attribs);
void push_local_extern_decl_alias (tree decl);
extern tree pushdecl (tree, bool hiding = false);
tree value, tree type, tree visible,
tree internal);
extern void add_module_namespace_decl (tree ns, tree decl);
+extern void add_imported_using_namespace (tree, tree);
enum WMB_Flags
{
--- /dev/null
+// PR c++/122915
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi imagine }
+
+export module imagine;
+namespace ns {}
+export namespace ig {
+ using namespace ns;
+}
--- /dev/null
+// PR c++/122915
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi tests:part }
+
+export module tests:part;
+namespace abc {}
+namespace part {
+ export using namespace abc;
+}
--- /dev/null
+// PR c++/122915
+// { dg-additional-options "-fmodules -fdump-lang-module" }
+// { dg-module-cmi tests }
+
+export module tests;
+export import :part;
+import imagine;
+using namespace ig;
+
+// { dg-final { scan-lang-dump {Writing using-directive in '::' for '::ig'} module } }
+// { dg-final { scan-lang-dump {Writing using-directive in '::part' for '::abc'} module } }
+// { dg-final { scan-lang-dump-not {Writing using-directive in '::ig' for '::ns'} module } }
--- /dev/null
+// PR c++/122915
+// { dg-additional-options "-fmodules" }
+
+module tests;
+
+namespace ns { using T = int; };
+T x = 123;
+
+namespace abc { using U = double; };
+part::U y = 3.14;