Skip to content
Snippets Groups Projects
Commit c592310d authored by Nathaniel Shead's avatar Nathaniel Shead
Browse files

c++/modules: Fix merging of GM entities in partitions [PR114950]


Currently name lookup generally seems to assume that all entities
declared within a named module (partition) are attached to said module,
which is not true for GM entities (e.g. via extern "C++"), and causes
issues with deduplication.

This patch fixes the issue by ensuring that module attachment of a
declaration is consistently used to handling merging.  Handling this
exposes some issues with deduplicating temploid friends; to resolve this
we always create the BINDING_SLOT_PARTITION slot so that we have
somewhere to place attached names (from any module).

This doesn't yet completely handle issues with allowing otherwise
conflicting temploid friends from different modules to co-exist in the
same module if neither are reachable from the other via name lookup.

	PR c++/114950

gcc/cp/ChangeLog:

	* module.cc (trees_out::decl_value): Stream bit indicating
	imported temploid friends early.
	(trees_in::decl_value): Use this bit with key_mergeable.
	(trees_in::key_mergeable): Allow merging attached declarations
	if they're imported temploid friends (which must be namespace
	scope).
	(module_state::read_cluster): Check for GM entities that may
	require merging even when importing from partitions.
	* name-lookup.cc (enum binding_slots): Adjust comment.
	(get_fixed_binding_slot): Always create partition slot.
	(name_lookup::search_namespace_only): Support binding vectors
	with both partition and GM entities to dedup.
	(walk_module_binding): Likewise.
	(name_lookup::adl_namespace_fns): Likewise.
	(set_module_binding): Likewise.
	(check_module_override): Use attachment of the decl when
	checking overrides rather than named_module_p.
	(lookup_imported_hidden_friend): Use partition slot for finding
	mergeable template bindings.
	* name-lookup.h (set_module_binding): Split mod_glob_flag
	parameter into separate global_p and partition_p params.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/tpl-friend-13_e.C: Adjust error message.
	* g++.dg/modules/ambig-2_a.C: New test.
	* g++.dg/modules/ambig-2_b.C: New test.
	* g++.dg/modules/part-9_a.C: New test.
	* g++.dg/modules/part-9_b.C: New test.
	* g++.dg/modules/part-9_c.C: New test.
	* g++.dg/modules/tpl-friend-15.h: New test.
	* g++.dg/modules/tpl-friend-15_a.C: New test.
	* g++.dg/modules/tpl-friend-15_b.C: New test.
	* g++.dg/modules/tpl-friend-15_c.C: New test.

Signed-off-by: default avatarNathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: default avatarJason Merrill <jason@redhat.com>
parent c0ad382c
No related branches found
No related tags found
No related merge requests found
Showing with 148 additions and 54 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment