diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index e4c435fecbef566d9ba7daf33bc10151eb93e3d6..2c5c9d99b34aea515967fe9712a123ef79b47dd4 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9207,7 +9207,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } else if (fun) { - if (RECUR (fun, FUNCTION_POINTER_TYPE_P (fun) ? rval : any)) + if (TREE_TYPE (fun) + && FUNCTION_POINTER_TYPE_P (TREE_TYPE (fun))) + want_rval = rval; + else + want_rval = any; + if (RECUR (fun, want_rval)) /* Might end up being a constant function pointer. But it could also be a function object with constexpr op(), so we pass 'any' so that the underlying VAR_DECL is deemed diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C index 3f63a5b28d70c9e06443fc3cf8dfce7aa1217302..c63d26c931d9e3e7dbdca4b0ac74a715a98d0c25 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C @@ -15,10 +15,12 @@ struct P { }; void (*f)(P); +P (*h)(P); template<class T> constexpr bool g() { P x; f(x); // { dg-bogus "from here" } + f(h(x)); // { dg-bogus "from here" } return true; } diff --git a/gcc/testsuite/g++.dg/diagnostic/constexpr4.C b/gcc/testsuite/g++.dg/diagnostic/constexpr4.C new file mode 100644 index 0000000000000000000000000000000000000000..f37c01cac55abf140f44f16fc6070d21055ea6da --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/constexpr4.C @@ -0,0 +1,9 @@ +// Verify we diagnose a call to a non-constant function pointer ahead of time. +// { dg-do compile { target c++11 } } + +bool (*f)(int); + +template<int N> +void g() { + static_assert(f(N), ""); // { dg-error "non-constant|'f' is not usable" } +}