[PATCH] D131528: [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 10 11:12:12 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e458765aaef: [Clang] Restrict non fixed enum to a value outside the range of the enumeration… (authored by shafik).
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131528/new/
https://reviews.llvm.org/D131528
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2421,6 +2421,7 @@
constexpr E1 x1 = static_cast<E1>(-8);
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}}
+ E1 x2b = static_cast<E1>(8); // ok, not a constant expression context
constexpr E2 x3 = static_cast<E2>(-8);
// expected-error at -1 {{integer value -8 is outside the valid range of values [0, 7] for this enumeration type}}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13533,7 +13533,9 @@
return Info.Ctx.getTypeSize(DestType) == Info.Ctx.getTypeSize(SrcType);
}
- if (Info.Ctx.getLangOpts().CPlusPlus && DestType->isEnumeralType()) {
+ if (Info.Ctx.getLangOpts().CPlusPlus &&
+ Info.EvalMode == EvalInfo::EM_ConstantExpression &&
+ DestType->isEnumeralType()) {
const EnumType *ET = dyn_cast<EnumType>(DestType.getCanonicalType());
const EnumDecl *ED = ET->getDecl();
// Check that the value is within the range of the enumeration values.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131528.451575.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220810/7d38cc61/attachment-0001.bin>
More information about the cfe-commits
mailing list