c++/modules: Maintain attachment of temploid friends after duplicate_decls [PR122551]
The ICE in the PR is because we're attempting to create a binding for an
imported declaration. This is problematic because if there are
duplicates we'll stream via a tt_entity, but won't enable deduplication
on the relevant binding vectors which can cause issues.
The root cause seems to stem from us forgetting that we've produced a
declaration for this entity within our own module, and so the active
declaration is not purely from an imported entity. We also didn't
properly track that this entity has unusual module attachment and
despite being declared here without being an instantiation actually is
attached to a different module than the current one (which may have
caused other problems down the line). This patch fixes both of these
issues.
PR c++/122551
gcc/cp/ChangeLog:
* cp-tree.h (transfer_defining_module): Declare.
* decl.cc (duplicate_decls): Call it for all decls.
Remove now unnecessary equivalent logic for templates.
* module.cc (mangle_module): Add assertion.
(transfer_defining_module): New function.
gcc/testsuite/ChangeLog:
* g++.dg/modules/tpl-friend-20_a.C: New test.
* g++.dg/modules/tpl-friend-20_b.C: New test.
* g++.dg/modules/tpl-friend-20_c.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>