]> granicus.if.org Git - clang/commitdiff
PR43674: fix incorrect constant evaluation of 'switch' where no case
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Oct 2019 22:23:11 +0000 (22:23 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Oct 2019 22:23:11 +0000 (22:23 +0000)
label corresponds to the condition.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374954 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx1y.cpp

index 44593350945ec2d9c6d3b7536ee9cecba71c1c3e..a379a335b2f08d3f5d3d9a42f085d1cbc774cbd9 100644 (file)
@@ -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);
index 2a8304ebda64178adaabf31bbe98d9b0daf97426..614b39533dfcd152e2a84f731aab5d657cdada69 100644 (file)
@@ -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;