aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg/import-c/pr119761c.c
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2025-09-05 13:29:12 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2025-09-06 22:00:39 +1000
commit014873fdf4bb2e00d704f182aa78b3022019ef48 (patch)
tree6f5c6a2e14445bbe73703d222ad79255f6335360 /gcc/testsuite/gdc.dg/import-c/pr119761c.c
parentc39dbb652fafbb06507d23dcec6627ac9a9398cf (diff)
downloadgcc-master.zip
gcc-master.tar.gz
gcc-master.tar.bz2
c++/modules: Fix exported using-directive of imported namespace [PR121702]HEADtrunkmaster
Currently we represent exported using-directives as a list of indices into the namespace array that we stream. However this list of namespaces doesn't include any namespaces that we don't expose in this module's purview, and so we ICE. This patch reworks the handling to instead use the existing depset tracking for namespaces directly. This means that we don't need to build up a second lookup map when streaming, and we can reuse the logic in {read,write}_namespace. We do need to make sure that we create a depset for namespaces only referenced by a using-directive, though. I don't expect to be exporting large numbers of using-directives from a namespace, so for simplicity we stream the names as {parent, target} pairs. This also adjusts read handling so that we load the using-directives for any import (including indirect) if it's in the import list for the current TU. Otherwise we run into issues if the using-directive is in a namespace that is otherwise never referenced in the 'export import'ing module, because we never walk this namespace and so never know that we need to emit it. To do this the patch ensures that we calculate the import list before read_language is called. As a drive-by fix, I noticed that with modules 'add_using_namespace' will add duplicate using-directives because we compare usings against the target namespace, but we then push a wrapping USING_DECL instead. This reworks so that the contents of the structure is equivalent between modules and non-modules code. PR c++/121702 gcc/cp/ChangeLog: * module.cc (enum module_state_counts): New counter. (depset::hash::add_namespace_entities): Seed using-directive targets for later streaming. (module_state::write_namespaces): Don't handle using-directives here. (module_state::read_namespaces): Likewise. (module_state::write_using_directives): New function. (module_state::read_using_directives): New function. (module_state::write_counts): Log using-directives. (module_state::read_counts): Likewise. (module_state::write_begin): Stream using-directives. (module_state::read_language): Read using-directives if directly importing. (module_state::direct_import): Update current TU import list before calling read_language. * name-lookup.cc (add_using_namespace): Fix lookup of previous using-directives. * parser.cc (cp_parser_import_declaration): Don't set MK_EXPORTING when performing import_module. gcc/testsuite/ChangeLog: * g++.dg/modules/namespace-10_c.C: Add check for log dump. * g++.dg/modules/namespace-13_a.C: New test. * g++.dg/modules/namespace-13_b.C: New test. * g++.dg/modules/namespace-13_c.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Diffstat (limited to 'gcc/testsuite/gdc.dg/import-c/pr119761c.c')
0 files changed, 0 insertions, 0 deletions