c++: add __is_deducible trait [PR105841]
C++20 class template argument deduction for an alias template involves adding a constraint that the template arguments for the alias template can be deduced from the return type of the deduction guide for the underlying class template. In the standard, this is modeled as defining a class template with a partial specialization, but it's much more efficient to implement with a trait that directly tries to perform the deduction. The first argument to the trait is a template rather than a type, so various places needed to be adjusted to accommodate that. PR c++/105841 gcc/ChangeLog: * doc/extend.texi (Type Traits):: Document __is_deducible. gcc/cp/ChangeLog: * cp-trait.def (IS_DEDUCIBLE): New. * cxx-pretty-print.cc (pp_cxx_trait): Handle non-type. * parser.cc (cp_parser_trait): Likewise. * tree.cc (cp_tree_equal): Likewise. * pt.cc (tsubst_copy_and_build): Likewise. (type_targs_deducible_from): New. (alias_ctad_tweaks): Use it. * semantics.cc (trait_expr_value): Handle CPTK_IS_DEDUCIBLE. (finish_trait_expr): Likewise. * constraint.cc (diagnose_trait_expr): Likewise. * cp-tree.h (type_targs_deducible_from): Declare. gcc/testsuite/ChangeLog: * g++.dg/ext/is_deducible1.C: New test.
Showing
- gcc/cp/constraint.cc 3 additions, 0 deletionsgcc/cp/constraint.cc
- gcc/cp/cp-trait.def 1 addition, 0 deletionsgcc/cp/cp-trait.def
- gcc/cp/cp-tree.h 1 addition, 0 deletionsgcc/cp/cp-tree.h
- gcc/cp/cxx-pretty-print.cc 4 additions, 1 deletiongcc/cp/cxx-pretty-print.cc
- gcc/cp/parser.cc 16 additions, 4 deletionsgcc/cp/parser.cc
- gcc/cp/pt.cc 59 additions, 10 deletionsgcc/cp/pt.cc
- gcc/cp/semantics.cc 11 additions, 0 deletionsgcc/cp/semantics.cc
- gcc/cp/tree.cc 1 addition, 1 deletiongcc/cp/tree.cc
- gcc/doc/extend.texi 4 additions, 0 deletionsgcc/doc/extend.texi
- gcc/testsuite/g++.dg/ext/is_deducible1.C 31 additions, 0 deletionsgcc/testsuite/g++.dg/ext/is_deducible1.C
Loading
Please register or sign in to comment