-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Description
In https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562 @AaronBallman describes -Wenum-constexpr-conversion this way:
- Clang will now correctly diagnose as ill-formed a constant expression where an enum without a fixed underlying type is set to a value outside the range of the enumeration’s values.
enum E { Zero, One, Two, Three, Four };
constexpr E Val1 = (E)3; // Ok
constexpr E Val2 = (E)7; // Ok
constexpr E Val3 = (E)8; // Now diagnosed as out of the range [0, 7]
constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]I think the actual "range" of the enumeration is [0, 4] not [0, 7] and therefore clang should diagnose the second example (E)7.
Alternatively, the diagnostic should be described differently, in order to accurately specify the conditions that are being diagnosed. Perhaps instead of "outside the range of the enumeration's values" it should be "outside the range of the minimum-size bitfield needed to represent the range of the enumeration's values."
But I'd rather see this handled as a bug, and fixed accordingly.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer