[PATCH] D131307: [Clang] Allow downgrading to a warning the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 5 18:05:08 PDT 2022
shafik added inline comments.
================
Comment at: clang/lib/AST/ExprConstant.cpp:13532
- if (DestType->isEnumeralType()) {
+ if (Info.Ctx.getLangOpts().CPlusPlus && DestType->isEnumeralType()) {
const EnumType *ET = dyn_cast<EnumType>(DestType.getCanonicalType());
----------------
Changing this to a warning meaning it applied in more cases, so I need to explicitly restrict this to C++ contexts.
================
Comment at: clang/test/SemaCXX/MicrosoftCompatibility.cpp:242
ENUM *var = 0;
-ENUM var2 = (ENUM)3;
+ENUM var2 = (ENUM)0;
enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
----------------
This is undefined behavior, using `0` avoids the diagnostic and I believe still sticks to the intent of the test. Same below.
================
Comment at: clang/test/SemaCXX/compare.cpp:432
- // FIXME: We should warn about constructing this out-of-range numeration value.
- const E invalid = (E)-1;
- // ... but we should not warn about comparing against it.
----------------
This is UB and I don't think this applies anymore.
================
Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:2422
+ constexpr E1 x2 = static_cast<E1>(8);
+ // expected-error at -1 {{integer value 8 is outside the valid range of values [-8, 7] for this enumeration type}}
----------------
I kept this on the next line since when we turn this back into an error we will have two diagnostics again.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131307/new/
https://reviews.llvm.org/D131307
More information about the cfe-commits
mailing list