c++: Implement P2582R1, CTAD from inherited constructors
commit83088b331cde0843d65d316e554873ef6d7b6bca
authorPatrick Palka <ppalka@redhat.com>
Thu, 14 Dec 2023 15:18:48 +0000 (14 10:18 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 14 Dec 2023 15:18:48 +0000 (14 10:18 -0500)
tree1754c8a755e1ffcc6fb44de99142316005ef6506
parentd782ec8362eadc3169286eb1e39c631effd02323
c++: Implement P2582R1, CTAD from inherited constructors

This patch implements C++23 class template argument deduction from
inherited constructors, the mechanism for which relies on alias
CTAD which we already fully support.  The process for transforming
the return type of an inherited guide is specified in terms of a
partially specialized class template, but this patch implements it in
a simpler way, effectively performing ahead of time deduction instead
of instantiation time deduction.  I wasn't able to find an example for
which this implementation strategy makes a difference, but I didn't
look very hard.  Support seems good enough to advertise as complete
but there doesn't seem to be a feature-test macro update for this
feature yet.  There should be no functional change before C++23 mode.

There's a couple of FIXMEs, one in inherited_ctad_tweaks for recognizing
more forms of inherited constructors, and one in deduction_guides_for for
making the cache aware of base-class dependencies.

gcc/cp/ChangeLog:

* cp-tree.h (type_targs_deducible_from): Adjust return type.
* pt.cc (alias_ctad_tweaks): Also handle C++23 inherited CTAD.
(inherited_ctad_tweaks): Define.
(type_targs_deducible_from): Return the deduced arguments or
NULL_TREE instead of a bool.  Handle 'tmpl' being a TREE_LIST
representing a synthetic alias template.
(ctor_deduction_guides_for): Do inherited_ctad_tweaks for each
USING_DECL in C++23 mode.
(deduction_guides_for): Add FIXME for stale cache entries in
light of inherited CTAD.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction67.C: Accept in C++23 mode.
* g++.dg/cpp23/class-deduction-inherited1.C: New test.
* g++.dg/cpp23/class-deduction-inherited2.C: New test.
* g++.dg/cpp23/class-deduction-inherited3.C: New test.
* g++.dg/cpp23/class-deduction-inherited4.C: New test.
gcc/cp/cp-tree.h
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1z/class-deduction67.C
gcc/testsuite/g++.dg/cpp23/class-deduction-inherited1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/class-deduction-inherited2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/class-deduction-inherited3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/class-deduction-inherited4.C [new file with mode: 0644]