From: Chris Lattner Date: Sun, 6 Apr 2008 06:02:23 +0000 (+0000) Subject: finish up throw parsing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a2819a0a8e114bfa5a3c4fc4c97fa173155bae9;p=clang finish up throw parsing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49266 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 6b42fb5b08..c98a7f91f8 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -87,13 +87,21 @@ Parser::ExprResult Parser::ParseThrowExpression() { ExprResult Expr; SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token. - // FIXME: Anything that isn't an assignment-expression should bail out now. - if (Tok.is(tok::semi) || Tok.is(tok::r_paren) || Tok.is(tok::colon) || - Tok.is(tok::comma)) + // If the current token isn't the start of an assignment-expression, + // then the expression is not present. This handles things like: + // "C ? throw : (void)42", which is crazy but legal. + switch (Tok.getKind()) { // FIXME: move this predicate somewhere common. + case tok::semi: + case tok::r_paren: + case tok::r_square: + case tok::r_brace: + case tok::colon: + case tok::comma: return Actions.ActOnCXXThrow(ThrowLoc); - Expr = ParseAssignmentExpression(); - if (!Expr.isInvalid) - Expr = Actions.ActOnCXXThrow(ThrowLoc, Expr.Val); - return Expr; + default: + Expr = ParseAssignmentExpression(); + if (Expr.isInvalid) return Expr; + return Actions.ActOnCXXThrow(ThrowLoc, Expr.Val); + } }