This is a follow up question of Undefined behavior of constexpr static cast from int to scoped enum with non-fixed underlying type compiles in C++17 (same question for scoped enumerations). TLDR is that scoped enums always have a fixed underlying type (by default int, hence you can always cast from int to scoped enum).
I wonder if the following should or should not compile in C++17
enum E
{
A, B
};
constexpr E x = static_cast<E>(2);
This compiles with both GCC 9.3.0 and Clang 10.0.0 on Ubuntu 20.04.
My question is
- Should this compile?
- If it should, why?
See the other post for a detailed reasoning why I think it should not compile for unscoped enums. The same reasoning applies for this question as well.