This revision was automatically updated to reflect the committed changes. Closed by commit rG2608f553b8fd: [Clang] Tighten restrictions on enum out of range diagnostic (authored by shafik). Herald added a project: clang.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131704/new/ https://reviews.llvm.org/D131704 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 @@ -2455,4 +2455,18 @@ constexpr EMaxInt x20 = static_cast<EMaxInt>((long)__INT_MAX__+1); // expected-error@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}} } + +enum SortOrder { + AscendingOrder, + DescendingOrder +}; + +class A { + static void f(SortOrder order); +}; + +void A::f(SortOrder order) { + if (order == SortOrder(-1)) // ok, not a constant expression context + return; +} } Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -13533,8 +13533,7 @@ return Info.Ctx.getTypeSize(DestType) == Info.Ctx.getTypeSize(SrcType); } - if (Info.Ctx.getLangOpts().CPlusPlus && - Info.EvalMode == EvalInfo::EM_ConstantExpression && + if (Info.Ctx.getLangOpts().CPlusPlus && Info.InConstantContext && DestType->isEnumeralType()) { const EnumType *ET = dyn_cast<EnumType>(DestType.getCanonicalType()); const EnumDecl *ED = ET->getDecl();
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx11.cpp +++ clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -2455,4 +2455,18 @@ constexpr EMaxInt x20 = static_cast<EMaxInt>((long)__INT_MAX__+1); // expected-error@-1 {{integer value 2147483648 is outside the valid range of values [-2147483648, 2147483647] for this enumeration type}} } + +enum SortOrder { + AscendingOrder, + DescendingOrder +}; + +class A { + static void f(SortOrder order); +}; + +void A::f(SortOrder order) { + if (order == SortOrder(-1)) // ok, not a constant expression context + return; +} } Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -13533,8 +13533,7 @@ return Info.Ctx.getTypeSize(DestType) == Info.Ctx.getTypeSize(SrcType); } - if (Info.Ctx.getLangOpts().CPlusPlus && - Info.EvalMode == EvalInfo::EM_ConstantExpression && + if (Info.Ctx.getLangOpts().CPlusPlus && Info.InConstantContext && DestType->isEnumeralType()) { const EnumType *ET = dyn_cast<EnumType>(DestType.getCanonicalType()); const EnumDecl *ED = ET->getDecl();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits