]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: modules and using-directives
authorJason Merrill <jason@redhat.com>
Wed, 20 Nov 2024 22:46:54 +0000 (23:46 +0100)
committerJason Merrill <jason@redhat.com>
Wed, 28 May 2025 13:01:47 +0000 (09:01 -0400)
commit06b9c58c70a4fee7cc680aaeb5790aaadbb9fc77
treea5e3a87ab237a5b5f7743b411774bc89431dcb28
parentd4a2f9ba6ece32fb8500f10204fcf409aa26fbfb
c++: modules and using-directives

We weren't representing 'using namespace' at all in modules, which broke
some of the <chrono> literals tests.

This only represents exported using-declarations; others should be
irrelevant to importers, as any name lookup in the imported module that
would have cared about them was done while compiling the header unit.

I experimented with various approaches to representing them; this patch
handles them in read/write_namespaces, after the namespaces themselves.  I
spent a while pondering how to deal with the depset code in order to connect
them, but then realized it would be simpler to refer to them based on their
index in the array of namespaces.

Any using-directives from an indirect import are ignored, so in an export
import, any imported using-directives are exported again.

gcc/cp/ChangeLog:

* module.cc (module_state::write_namespaces): Write
using-directives.
(module_state::read_namespaces): And read them.
* name-lookup.cc (add_using_namespace): Add overload.  Build a
USING_DECL for modules.
(name_lookup::search_usings, name_lookup::queue_usings)
(using_directives_contain_std_p): Strip the USING_DECL.
* name-lookup.h: Declare it.
* parser.cc (cp_parser_import_declaration): Set MK_EXPORTING
for export import.

gcc/testsuite/ChangeLog:

* g++.dg/modules/namespace-8_a.C: New test.
* g++.dg/modules/namespace-8_b.C: New test.
* g++.dg/modules/namespace-9_a.C: New test.
* g++.dg/modules/namespace-9_b.C: New test.
* g++.dg/modules/namespace-10_a.C: New test.
* g++.dg/modules/namespace-10_b.C: New test.
* g++.dg/modules/namespace-10_c.C: New test.
* g++.dg/modules/namespace-11_a.C: New test.
* g++.dg/modules/namespace-11_b.C: New test.
* g++.dg/modules/namespace-11_c.C: New test.
14 files changed:
gcc/cp/module.cc
gcc/cp/name-lookup.cc
gcc/cp/name-lookup.h
gcc/cp/parser.cc
gcc/testsuite/g++.dg/modules/namespace-10_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-10_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-10_c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-11_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-11_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-11_c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-8_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-8_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-9_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/namespace-9_b.C [new file with mode: 0644]