Skip to content

Commit 61dadfc

Browse files
committed
PR43674: fix incorrect constant evaluation of 'switch' where no case
label corresponds to the condition. llvm-svn: 374954
1 parent 208e9c0 commit 61dadfc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4435,7 +4435,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info,
44354435
}
44364436

44374437
if (!Found)
4438-
return Scope.destroy() ? ESR_Failed : ESR_Succeeded;
4438+
return Scope.destroy() ? ESR_Succeeded : ESR_Failed;
44394439

44404440
// Search the switch body for the switch case and evaluate it from there.
44414441
EvalStmtResult ESR = EvaluateStmt(Result, Info, SS->getBody(), Found);

clang/test/SemaCXX/constant-expression-cxx1y.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ namespace assignment_op {
627627
}
628628

629629
namespace switch_stmt {
630+
constexpr bool no_such_case(int n) {
631+
switch (n) { case 1: return false; }
632+
return true;
633+
}
634+
static_assert(no_such_case(0), "");
635+
630636
constexpr int f(char k) {
631637
bool b = false;
632638
int z = 6;

0 commit comments

Comments
 (0)