[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
Tue Aug 9 15:56:40 PDT 2022


shafik created this revision.
shafik added reviewers: erichkeane, aaron.ballman, zatrazz.
Herald added a project: All.
shafik requested review of this revision.

In D131307 <https://reviews.llvm.org/D131307> we allowed the diagnostic to be turned into a warning for a transition period.

This had the side effect of triggering the warning in contexts not required to be constant expression. This change will restrict the diagnostic to constant expression contexts. This should reduce the fallout of this diagnostic.


https://reviews.llvm.org/D131528

Files:
  clang/lib/AST/ExprConstant.cpp


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.451294.patch
Type: text/x-patch
Size: 706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220809/182ad58c/attachment.bin>


More information about the cfe-commits mailing list