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@-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@-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.
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@-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@-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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits