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

c++/modules: Ensure deduction guides are always reachable [PR115231]


Deduction guides are represented as 'normal' functions currently, and
have no special handling in modules.  However, this causes some issues;
by [temp.deduct.guide] a deduction guide is not found by normal name
lookup and instead all reachable deduction guides for a class template
should be considered, but this does not happen currently.

To solve this, this patch ensures that all deduction guides are
considered exported to ensure that they are always visible to importers
if they are reachable.  Another alternative here would be to add a new
kind of "all reachable" flag to name lookup, but that is complicated by
some difficulties in handling GM entities; this may be a better way to
go if more kinds of entities end up needing this handling, however.

Another issue here is that because deduction guides are "unrelated"
functions, they will usually get discarded from the GMF, so this patch
ensures that when finding dependencies, GMF deduction guides will also
have bindings created.  We do this in find_dependencies so that we don't
unnecessarily create bindings for GMF deduction guides that are never
reached; for consistency we do this for *all* deduction guides, not just
GM ones.  We also make sure that the opposite (a deduction guide being
the only purview reference to a GMF template) correctly marks it as
reachable.

Finally, when merging deduction guides from multiple modules, the name
lookup code may now return two-dimensional overload sets, so update
callers to match.

As a small drive-by improvement this patch also updates the error pretty
printing code to add a space before the '->' when printing a deduction
guide, so we get 'S(int) -> S<int>' instead of 'S(int)-> S<int>'.

	PR c++/115231

gcc/cp/ChangeLog:

	* error.cc (dump_function_decl): Add a space before '->' when
	printing deduction guides.
	* module.cc (depset::hash::add_binding_entity): Don't create
	bindings for guides here, only mark dependencies.
	(depset::hash::add_deduction_guides): New.
	(depset::hash::find_dependencies): Add deduction guide
	dependencies for a class template.
	(module_state::write_cluster): Always consider deduction guides
	as exported.
	* pt.cc (deduction_guides_for): Use 'lkp_iterator' instead of
	'ovl_iterator'.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/dguide-1_a.C: New test.
	* g++.dg/modules/dguide-1_b.C: New test.
	* g++.dg/modules/dguide-2_a.C: New test.
	* g++.dg/modules/dguide-2_b.C: New test.
	* g++.dg/modules/dguide-3_a.C: New test.
	* g++.dg/modules/dguide-3_b.C: New test.
	* g++.dg/modules/dguide-3_c.C: New test.
	* g++.dg/modules/dguide-3_d.C: New test.

Signed-off-by: default avatarNathaniel Shead <nathanieloshead@gmail.com>
parent b7f71961
No related branches found
No related tags found
No related merge requests found
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