diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-10-15 22:23:11 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-10-15 22:23:11 +0000 |
commit | ed4dbd72ed336ea1b7ae8a2165bc0f7b3eccb31c (patch) | |
tree | 114dd132858492a5852f72919cf84b7adfd8531b | |
parent | 5e5092b6825108321f5964376baef9fb136419db (diff) |
PR43674: fix incorrect constant evaluation of 'switch' where no case
label corresponds to the condition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374954 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/ExprConstant.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/constant-expression-cxx1y.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 4459335094..a379a335b2 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -4435,7 +4435,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info, } 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. EvalStmtResult ESR = EvaluateStmt(Result, Info, SS->getBody(), Found); diff --git a/test/SemaCXX/constant-expression-cxx1y.cpp b/test/SemaCXX/constant-expression-cxx1y.cpp index 2a8304ebda..614b39533d 100644 --- a/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/test/SemaCXX/constant-expression-cxx1y.cpp @@ -627,6 +627,12 @@ namespace assignment_op { } 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) { bool b = false; int z = 6; |