-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Enable Wenum-constexpr-conversion also in system headers and … (
#67528) …macros As per review comments on https://reviews.llvm.org/D150226, we should allow for one more release before turning this warning into a hard error, by making it visible in system headers and macros, so that people are aware of it and can work on it.
- Loading branch information
1 parent
a502ddd
commit e7a6171
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// System header for testing that -Wenum-constexpr-conversion leads to an error | ||
// when included in user code, or when the system macro is used. | ||
|
||
enum SystemEnum | ||
{ | ||
a = 0, | ||
b = 1, | ||
}; | ||
|
||
void testValueInRangeOfEnumerationValuesInSystemHeader() | ||
{ | ||
constexpr SystemEnum x1 = static_cast<SystemEnum>(123); | ||
// expected-error@-1 {{integer value 123 is outside the valid range of values [0, 1] for the enumeration type 'SystemEnum'}} | ||
|
||
const SystemEnum x2 = static_cast<SystemEnum>(123); // ok, not a constant expression context | ||
} | ||
|
||
#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \ | ||
constexpr SystemEnum system_enum = static_cast<SystemEnum>(123) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters