Author: rsmith Date: Tue Oct 15 15:23:11 2019 New Revision: 374954 URL: http://llvm.org/viewvc/llvm-project?rev=374954&view=rev Log: PR43674: fix incorrect constant evaluation of 'switch' where no case label corresponds to the condition.
Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=374954&r1=374953&r2=374954&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Oct 15 15:23:11 2019 @@ -4435,7 +4435,7 @@ static EvalStmtResult EvaluateSwitch(Stm } 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); Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=374954&r1=374953&r2=374954&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original) +++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Tue Oct 15 15:23:11 2019 @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits