The fail-fast predicate uses_deducible_template_parms used by unify_one_argument is neglecting to look inside the noexcept-spec of a function type, and this causes deduction to fail for the below testcase since the noexcept-spec is the only part of the type which contains a deducible template parameter.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/80951 gcc/cp/ChangeLog: * pt.cc (uses_deducible_template_parms): Consider the noexcept-spec of a function type. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/noexcept-type25.C: New test. --- gcc/cp/pt.cc | 5 +++++ gcc/testsuite/g++.dg/cpp1z/noexcept-type25.C | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type25.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c7af4712d8b..97d247f6684 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -22398,6 +22398,11 @@ uses_deducible_template_parms (tree type) for (; parm; parm = TREE_CHAIN (parm)) if (uses_deducible_template_parms (TREE_VALUE (parm))) return true; + if (flag_noexcept_type + && TYPE_RAISES_EXCEPTIONS (type) + && TREE_PURPOSE (TYPE_RAISES_EXCEPTIONS (type)) + && deducible_expression (TREE_PURPOSE (TYPE_RAISES_EXCEPTIONS (type)))) + return true; } return false; diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type25.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type25.C new file mode 100644 index 00000000000..ef5c8265541 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type25.C @@ -0,0 +1,13 @@ +// PR c++/80951 +// { dg-do compile { target c++17 } } + +void f() noexcept; +void g(); + +template<bool E> +constexpr bool h(void (*)() noexcept(E)) { + return E; +} + +static_assert(h(f)); +static_assert(!h(g)); -- 2.35.1.46.g38062e73e0