Static assert fails in constexpr template

67 Views Asked by At

When I try to compile the following code using clang the static assertion fails:

#include <type_traits>

template<typename T>
int TypeTest()
{
    if constexpr (std::is_same_v<bool, T>) {
        return 1;
    } else if constexpr (std::is_same_v<std::uint8_t, T>) {
        return 2;
    } else {
        static_assert(false, "check");

        return 3;
    }
}

int main()
{
    return TypeTest<bool>();
}

It even fails if there is no TypeTest is not used at all in the code. Can anybody tell me how the compiler arrives at the static assert during compile time?

0

There are 0 best solutions below