I have an issue with std::is_invocable in the following program:
#include <iostream>
#include <type_traits>
void g() {}
template<bool B, typename T>
void f(T t) {
if constexpr (B)
g(t);
}
int main() {
std::cerr << std::boolalpha <<
std::is_invocable_v<decltype(&f<true, int>), int> << std::endl;
}
I would have expected the program output to be false since f<true, int> cannot be instantiated. However, GCC (as of 10.0.1 20200224) does not compile with the error message being
test.cpp: In instantiation of 'void f(T) [with bool B = true; T = int]':
test.cpp:14:51: required from here
test.cpp:9:10: error: too many arguments to function 'void g()'
9 | g(t);
| ~^~~
test.cpp:4:6: note: declared here
4 | void g() {}
|
and Clang (as of 11.0.0) even prints true.
What is the correct behavior in this case?