yronglin created this revision. Herald added a project: All. yronglin requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Signed-off-by: yronglin <yronglin...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153296 Files: clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/switch.cpp Index: clang/test/SemaCXX/switch.cpp =================================================================== --- clang/test/SemaCXX/switch.cpp +++ clang/test/SemaCXX/switch.cpp @@ -146,3 +146,15 @@ } } // namespace EmptyEnum + +constexpr int foo(unsigned char c) { + switch (f) { // expected-error {{use of undeclared identifier}} + case 0: + return 7; + default: + break; + } + return 0; +} + +static_assert(foo('d')); // expected-error {{static assertion expression is not an integral constant expression}} Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -4983,7 +4983,9 @@ !EvaluateDecl(Info, SS->getConditionVariable())) return ESR_Failed; if (SS->getCond()->isValueDependent()) { - if (!EvaluateDependentExpr(SS->getCond(), Info)) + // Stop evaluate if condition expression contains errors. + if (SS->getCond()->containsErrors() || + !EvaluateDependentExpr(SS->getCond(), Info)) return ESR_Failed; } else { if (!EvaluateInteger(SS->getCond(), Value, Info))
Index: clang/test/SemaCXX/switch.cpp =================================================================== --- clang/test/SemaCXX/switch.cpp +++ clang/test/SemaCXX/switch.cpp @@ -146,3 +146,15 @@ } } // namespace EmptyEnum + +constexpr int foo(unsigned char c) { + switch (f) { // expected-error {{use of undeclared identifier}} + case 0: + return 7; + default: + break; + } + return 0; +} + +static_assert(foo('d')); // expected-error {{static assertion expression is not an integral constant expression}} Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -4983,7 +4983,9 @@ !EvaluateDecl(Info, SS->getConditionVariable())) return ESR_Failed; if (SS->getCond()->isValueDependent()) { - if (!EvaluateDependentExpr(SS->getCond(), Info)) + // Stop evaluate if condition expression contains errors. + if (SS->getCond()->containsErrors() || + !EvaluateDependentExpr(SS->getCond(), Info)) return ESR_Failed; } else { if (!EvaluateInteger(SS->getCond(), Value, Info))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits