We're incorrectly rejecting the below testcase during template argument coercion because invalid_nontype_parm_type_p returns true for DEPENDENT_OPERATOR_TYPE.
This patch fixes this by partially rewriting invalid_nontype_parm_type_p in terms of WILDCARD_TYPE_P, of which DEPENDENT_OPERATOR_TYPE is one. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/104074 gcc/cp/ChangeLog: * pt.c (invalid_nontype_parm_type_p): Use WILDCARD_TYPE_P so that we return false for DEPENDENT_OPERATOR_TYPE too. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nontype-auto20.C: New test. --- gcc/cp/pt.c | 14 ++++++-------- gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C | 5 +++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0fa4a162354..e57613488d4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -26931,16 +26931,14 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain) } return false; } - else if (TREE_CODE (type) == TYPENAME_TYPE) - return false; - else if (TREE_CODE (type) == DECLTYPE_TYPE) - return false; else if (TREE_CODE (type) == NULLPTR_TYPE) return false; - /* A bound template template parm could later be instantiated to have a valid - nontype parm type via an alias template. */ - else if (cxx_dialect >= cxx11 - && TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM) + else if (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM + && cxx_dialect < cxx11) + /* Fall through; before C++11 alias templates, a bound ttp + always instantiates to a class type. */; + else if (WILDCARD_TYPE_P (type)) + /* Any other wildcard type not already handled above is allowed. */ return false; else if (TREE_CODE (type) == COMPLEX_TYPE) /* Fall through. */; diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C new file mode 100644 index 00000000000..03eea91ce09 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C @@ -0,0 +1,5 @@ +// PR c++/104074 +// { dg-do compile { target c++17 } } + +template<auto> class gr_sp; +template<class T> using gr_rp = gr_sp<+T::recycle>; -- 2.35.0.rc1