]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Don't emit imported deduction guides [PR117397]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 11 Jan 2025 17:00:56 +0000 (04:00 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 14 Jan 2025 11:06:33 +0000 (22:06 +1100)
commit87ffd205fe0f4cbabd3d22cba815b02c0466d9ed
tree62fac74bc1bab6d4631f1938c5cede2c2a400276
parent744a59f3f55bfc890f755c57c72919566e1bcad5
c++/modules: Don't emit imported deduction guides [PR117397]

The ICE in the linked PR is caused because name lookup finds duplicate
copies of the deduction guides, causing a checking assert to fail.

This is ultimately because we're exporting an imported guide; when name
lookup processes 'dguide-5_b.H' it goes via the 'tt_entity' path and
just returns the entity from 'dguide-5_a.H'.  Because this doesn't ever
go through 'key_mergeable' we never set 'BINDING_VECTOR_GLOBAL_DUPS_P'
and so deduping is not engaged, allowing duplicate results.

Currently I believe this to be a perculiarity of the ANY_REACHABLE
handling for deduction guides; in no other case that I can find do we
emit bindings purely to imported entities.  As such, this patch fixes
this problem from that end, by ensuring that we simply do not emit any
imported deduction guides.  This avoids the ICE because no duplicates
need deduping to start with, and should otherwise have no functional
change because lookup of deduction guides will look at all reachable
modules (exported or not) regardless.

Since we're now deliberately not emitting imported deduction guides we
can use LOOK_want::NORMAL instead of LOOK_want::ANY_REACHABLE, since the
extra work to find as-yet undiscovered deduction guides in transitive
importers is not necessary here.

PR c++/117397

gcc/cp/ChangeLog:

* module.cc (depset::hash::add_deduction_guides): Don't emit
imported deduction guides.
(depset::hash::finalize_dependencies): Add check for any
bindings referring to imported entities.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dguide-5_a.H: New test.
* g++.dg/modules/dguide-5_b.H: New test.
* g++.dg/modules/dguide-5_c.H: New test.
* g++.dg/modules/dguide-6.h: New test.
* g++.dg/modules/dguide-6_a.C: New test.
* g++.dg/modules/dguide-6_b.C: New test.
* g++.dg/modules/dguide-6_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/dguide-5_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-5_b.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-5_c.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-6.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-6_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-6_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/dguide-6_c.C [new file with mode: 0644]