]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Maintain attachment of temploid friends after duplicate_decls [PR122551]
authorNathaniel Shead <nathanieloshead@gmail.com>
Tue, 11 Nov 2025 06:13:46 +0000 (17:13 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 13 Nov 2025 11:29:19 +0000 (22:29 +1100)
commit5fbcd8a57a0f2524259df87db5c6c82b757bf2e6
tree51505b7dc9bbc3c8754b5d53da96465c6020d959
parente840037fccceff0ad585946ff4d454f220c51759
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>
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/tpl-friend-20_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tpl-friend-20_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tpl-friend-20_c.C [new file with mode: 0644]