We reject this well-formed test because the following error was triggering even in a SFINAE context, while it should not: https://en.cppreference.com/w/cpp/language/sfinae says that "attempting to give an invalid type to a non-type template parameter" is a SFINAE error.
I wonder if the tf_error check should be used more in that function. But this is enough for this particular testcase. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-09-27 Marek Polacek <pola...@redhat.com> PR c++/91923 - failure-to-SFINAE with class type NTTP in C++17. * pt.c (invalid_nontype_parm_type_p): Only emit errors when tf_error. * g++.dg/cpp0x/nontype5.C: New test. diff --git gcc/cp/pt.c gcc/cp/pt.c index e5d64989b32..e71403460b0 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -25235,8 +25235,9 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain) { if (cxx_dialect < cxx2a) { - error ("non-type template parameters of class type only available " - "with %<-std=c++2a%> or %<-std=gnu++2a%>"); + if (complain & tf_error) + error ("non-type template parameters of class type only available " + "with %<-std=c++2a%> or %<-std=gnu++2a%>"); return true; } if (dependent_type_p (type)) diff --git gcc/testsuite/g++.dg/cpp0x/nontype5.C gcc/testsuite/g++.dg/cpp0x/nontype5.C new file mode 100644 index 00000000000..c31134581aa --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/nontype5.C @@ -0,0 +1,17 @@ +// PR c++/91923 - failure-to-SFINAE with class type NTTP in C++17. +// { dg-do compile { target c++11 } } + +template<typename T> +constexpr bool is_integral_(...) { + return false; +} +template<typename T, T = 1> +constexpr bool is_integral_(long) { + return true; +} + +static_assert(is_integral_<int>(42), ""); +static_assert(!is_integral_<void>(42), ""); + +struct S {}; +static_assert(!is_integral_<S>(42), "");