c++/modules: Fix ICE when writing imported using-directive [PR122915]
The crash in the PR is caused because we are attempting to write a
using-directive that we never made a dep for. This should only happen
for imported using-directives, where if we never opened the relevant
namespace in the module purview we don't think there's anything
interesting to discover and so never walk it.
There's actually no reason we need to emit imported using-directives at
all, however, unless they came from a partition, because importers will
be able to get that directive directly from the originating module if it
was going to be visible anyway. And we will always walk and create a
dependency (marked !import_p) for partition decls. So this patch fixes
the ICE by just skipping such cases.
To help validate this the patch also starts setting DECL_MODULE_IMPORT_P
correctly for using-directives.
PR c++/122915
gcc/cp/ChangeLog:
* module.cc (module_state::write_using_directives): Don't emit
imported using-directives.
(module_state::read_using_directives): Rename
add_using_namespace to add_imported_using_namespace.
* name-lookup.cc (add_using_namespace): Handle imported
using-directives.
(add_imported_using_namespace): Rename to match new
functionality.
* name-lookup.h (add_using_namespace): Rename to...
(add_imported_using_namespace): ...this.
gcc/testsuite/ChangeLog:
* g++.dg/modules/namespace-16_a.C: New test.
* g++.dg/modules/namespace-16_b.C: New test.
* g++.dg/modules/namespace-16_c.C: New test.
* g++.dg/modules/namespace-16_d.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>