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 | 61dadfc894c566ce0af6163159ba0ba76d8007ad (patch) | |
| tree | 564b176c531c3550ef041eaa6de2a0557c6a0fb0 | |
| parent | 208e9c01fc094cedbcf47f39a902cff13dce0039 (diff) | |
| download | bcm5719-llvm-61dadfc894c566ce0af6163159ba0ba76d8007ad.tar.gz bcm5719-llvm-61dadfc894c566ce0af6163159ba0ba76d8007ad.zip | |
PR43674: fix incorrect constant evaluation of 'switch' where no case
label corresponds to the condition.
llvm-svn: 374954
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx1y.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 44593350945..a379a335b2f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx1y.cpp index 2a8304ebda6..614b39533df 100644 --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/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; |

