]> granicus.if.org Git - clang/commitdiff
Fixup parsing for (throw,throw) and __extension__ throw 1.
authorMike Stump <mrs@apple.com>
Fri, 15 May 2009 21:47:08 +0000 (21:47 +0000)
committerMike Stump <mrs@apple.com>
Fri, 15 May 2009 21:47:08 +0000 (21:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71897 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/Parser/cxx-throw.cpp [new file with mode: 0644]

index bfbac3ac26828ff4c3990835ac5d7159852fe8f3..c3a38b1fe22a58b58b81384f03d10b933d4be855 100644 (file)
@@ -201,10 +201,7 @@ static prec::Level getBinOpPrecedence(tok::TokenKind Kind,
 ///         expression ',' assignment-expression
 ///
 Parser::OwningExprResult Parser::ParseExpression() {
-  if (Tok.is(tok::kw_throw))
-    return ParseThrowExpression();
-
-  OwningExprResult LHS(ParseCastExpression(false));
+  OwningExprResult LHS(ParseAssignmentExpression());
   if (LHS.isInvalid()) return move(LHS);
 
   return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
@@ -228,11 +225,7 @@ Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
 /// process of disambiguating between an expression and a declaration.
 Parser::OwningExprResult
 Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
-  // FIXME: The handling for throw is almost certainly wrong.
-  if (Tok.is(tok::kw_throw))
-    return ParseThrowExpression();
-
-  OwningExprResult LHS(ParseCastExpression(false));
+  OwningExprResult LHS(ParseAssignmentExpression());
   if (LHS.isInvalid()) return move(LHS);
 
   LHS = Actions.ActOnUnaryOp(CurScope, ExtLoc, tok::kw___extension__,
diff --git a/test/Parser/cxx-throw.cpp b/test/Parser/cxx-throw.cpp
new file mode 100644 (file)
index 0000000..968ef46
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+int i;
+
+void foo() {
+  (throw,throw);
+  (1 ? throw 1 : throw 2);
+  throw int(1);
+  throw;
+  throw 1;
+  throw;
+  1 ? throw : (void)42;
+  // gcc doesn't parse the below, but we do
+  __extension__ throw 1;
+  (void)throw;              // expected-error {{expected expression}}
+}