PR43674: fix incorrect constant evaluation of 'switch' where no case

label corresponds to the condition.

llvm-svn: 374954
This commit is contained in:
Richard Smith 2019-10-15 22:23:11 +00:00
parent 208e9c01fc
commit 61dadfc894
2 changed files with 7 additions and 1 deletions

View File

@ -4435,7 +4435,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info,
} }
if (!Found) if (!Found)
return Scope.destroy() ? ESR_Failed : ESR_Succeeded; return Scope.destroy() ? ESR_Succeeded : ESR_Failed;
// Search the switch body for the switch case and evaluate it from there. // Search the switch body for the switch case and evaluate it from there.
EvalStmtResult ESR = EvaluateStmt(Result, Info, SS->getBody(), Found); EvalStmtResult ESR = EvaluateStmt(Result, Info, SS->getBody(), Found);

View File

@ -627,6 +627,12 @@ namespace assignment_op {
} }
namespace switch_stmt { namespace switch_stmt {
constexpr bool no_such_case(int n) {
switch (n) { case 1: return false; }
return true;
}
static_assert(no_such_case(0), "");
constexpr int f(char k) { constexpr int f(char k) {
bool b = false; bool b = false;
int z = 6; int z = 6;