https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554
--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Melissa from comment #0)
> Clang errors on this case, so it's possible that my code is invalid: Is it
> legal to compare a function pointer against null in a constant-expression?
The example is ill-formed because the condition of 'if constexpr' is more
restricted than that of normal 'if': It expects "a contextually converted
constant expression of type bool" and [expr.const] p10 lists the allowed
conversions in this case. This list omits the boolean conversions
([conv.bool]).
But the example would become valid when rewritten as follows:
int meow() { return 1; }
void kitty(int);
template <int (*F)()>
void test() {
if constexpr (bool(F)) {
kitty(F());
} else {
kitty(2);
}
}
template void test<nullptr>();
template void test<meow>();