From 51cfee88b37794cb98ee948c142884044a74e1fb Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 26 Jul 2018 18:41:30 +0000 Subject: Refactor checking of switch conditions and case values. Check each case value in turn while parsing it, performing the conversion to the switch type within the context of the expression itself. This will become necessary in order to properly handle cleanups for temporaries created as part of the case label (in an upcoming patch). For now it's just good hygiene. This necessitates moving the checking for the switch condition itself to earlier, so that the destination type is available when checking the case labels. As a nice side-effect, we get slightly improved diagnostic quality and error recovery by separating the case expression checking from the case statement checking and from tracking whether there are discarded case labels. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338056 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseExpr.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/Parse/ParseExpr.cpp') diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d96dc5b362..6904906403 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -217,6 +217,14 @@ ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) { return ParseConstantExpressionInExprEvalContext(isTypeCast); } +ExprResult Parser::ParseCaseExpression(SourceLocation CaseLoc) { + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); + ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); + ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); + return Actions.ActOnCaseExpr(CaseLoc, Res); +} + /// Parse a constraint-expression. /// /// \verbatim -- cgit v1.2.1