The following static_assert
should be discarded being in the false branch of if constexpr
, yet compilation fails due to assert failure:
#include <type_traits>
template <class T>
constexpr bool f() {
if constexpr (std::is_same<T, int>::value) return true;
else static_assert(false, "message");
}
int main () {
if constexpr (f<int>()) return 1;
return 0;
}
I'd expect that the discarded branch of if constexpr
wouldn't be evaluated because f
is instantiated with type int
.
Compiled with Gcc 7.2 (-std=c++17)