At the entry of reinterpret_cast
, cppref says:
An expression of integral, enumeration, pointer, or pointer-to-member type can be converted to its own type.The resulting value is the same as the value of expression. (since C++11)
However, the following code cannot be compiled (clang 5.0 with -std=c++1z
):
enum class A : int {};
int main()
{
A a{ 0 };
reinterpret_cast<int>(a); // error : reinterpret_cast from 'A' to 'int' is not allowed
}
Why does reinterpret_cast
not behave as the C++ standard says?