diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4889,6 +4889,9 @@ static bool EvaluateDependentExpr(const Expr *E, EvalInfo &Info) { assert(E->isValueDependent()); + // Stop evaluate if E is a RecoveryExpr. + if (isa(E)) + return false; if (Info.noteSideEffect()) return true; assert(E->containsErrors() && "valid value-dependent expression should never " diff --git a/clang/test/SemaCXX/switch.cpp b/clang/test/SemaCXX/switch.cpp --- a/clang/test/SemaCXX/switch.cpp +++ b/clang/test/SemaCXX/switch.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s void test() { bool x = true; @@ -146,3 +147,17 @@ } } // namespace EmptyEnum + +#if __cplusplus >= 201703L +constexpr int foo(unsigned char c) { + switch (unknown_value) { // 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}} +#endif