I have a function test, which prints out the underlying type of an enum parameter:
enum class TestEnum : uint32_t
{
};
template<typename TEnum>
void test(TEnum v)
{ // Line 12
if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,int8_t>)
std::cout<<"int8"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,uint8_t>)
std::cout<<"uint8"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,int16_t>)
std::cout<<"int16"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,uint16_t>)
std::cout<<"uint16"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,int32_t>)
std::cout<<"int32"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,uint32_t>)
std::cout<<"uint32"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,int64_t>)
std::cout<<"int64"<<std::endl;
else if constexpr (std::is_same_v<std::underlying_type_t<TEnum>,uint64_t>)
std::cout<<"uint64"<<std::endl;
else
static_assert(false,"Unsupported enum type!");
}
int main(int argc,char *argv[])
{
TestEnum e {};
test<TestEnum>(e);
return EXIT_SUCCESS;
}
The program compiles and runs fine in Visual Studio 2017 (with ISO C++17), however the last else is underlined in red with the following message:
expected a statement
detected during instantiation of "void test(TEnum v) [with TEnum=TestEnum]" at line 12
(I've tried using else constexpr instead of just else, but that doesn't seem to matter.)
If I remove the last else if-branch (the one checking for uint64_t), the error disappears:
Is this a bug in Visual Studio, or am I doing something that I shouldn't?