Description
The -Wenum-constexpr-conversion
warning was created to account for the fact that casting integers to enums outside of the valid range of the enum is UB in C++17. Constant expressions invoking UB lead to an ill-formed program.
The current behavior of Clang is that it does warn and it does error, but the message is nevertheless a warning that the user can easily suppress via -Wno-enum-constexpr-conversion
.
Since the program is ill-formed, I don't think this should be a warning that can be disabled. Just like one can't disable the warning in this ill-formed code:
constexpr int x[10]{};
constexpr int y = x[10];
Therefore I propose to make the diagnostic a hard error that cannot be disabled. Additionally, this "hard error" behavior should only be active in C++17 (it's currently active in for any standard).
The warning could be repurposed to be a general warning that one can enable, and is active not only in constexpr
expressions, but in any expression that involves casting an integer to an enum.