diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-06-15 22:50:14 +1000 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-08-07 11:49:47 +1000 |
commit | ca287145f23ec3ea987fc2eacde3994096cc528e (patch) | |
tree | a0b762064f6cb6e3d7e131c200535cb7b6c0630d /gcc/cp/pt.cc | |
parent | b7f719612515a86d1d2a36e24b02ade3f0904e10 (diff) | |
download | gcc-ca287145f23ec3ea987fc2eacde3994096cc528e.zip gcc-ca287145f23ec3ea987fc2eacde3994096cc528e.tar.gz gcc-ca287145f23ec3ea987fc2eacde3994096cc528e.tar.bz2 |
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: Nathaniel Shead <nathanieloshead@gmail.com>
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r-- | gcc/cp/pt.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 9a4ff55..2db5921 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30721,7 +30721,7 @@ deduction_guides_for (tree tmpl, bool &any_dguides_p, tsubst_flags_t complain) else { cands = ctor_deduction_guides_for (tmpl, complain); - for (ovl_iterator it (guides); it; ++it) + for (lkp_iterator it (guides); it; ++it) cands = lookup_add (*it, cands); } |