https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122915
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <[email protected]>: https://gcc.gnu.org/g:6a83030557ccceef5c12e8b45d6bcd5ba274232b commit r16-5811-g6a83030557ccceef5c12e8b45d6bcd5ba274232b Author: Nathaniel Shead <[email protected]> Date: Mon Dec 1 23:32:40 2025 +1100 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 <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
