]> granicus.if.org Git - clang/commitdiff
change ParseStatementOrDeclaration to emit the 'missing ;' with
authorChris Lattner <sabre@nondot.org>
Sun, 14 Jun 2009 00:23:56 +0000 (00:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Jun 2009 00:23:56 +0000 (00:23 +0000)
ExpectAndConsume instead of custom diag logic.  This gets us an
insertion hint and positions the ; at the end of the line
instead of on the next token.  Before:

t.c:5:1: error: expected ';' after return statement
}
^

after:

t.c:4:11: error: expected ';' after return statement
  return 4
          ^
          ;

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

lib/Parse/ParseStmt.cpp
test/Parser/statements.c

index 8cdcd517cab04fbd915043ff630486092d3881a2..955f00d7a0b5fc41113b6dd08a3299ee0a15202b 100644 (file)
@@ -180,10 +180,14 @@ Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
   if (Tok.is(tok::semi)) {
     ConsumeToken();
   } else if (!Res.isInvalid()) {
-    Diag(Tok, diag::err_expected_semi_after_stmt) << SemiError;
+    // If the result was valid, then we do want to diagnose this.  Use
+    // ExpectAndConsume to emit the diagnostic, even though we know it won't
+    // succeed.
+    ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
     // Skip until we see a } or ;, but don't eat it.
     SkipUntil(tok::r_brace, true, true);
   }
+  
   return move(Res);
 }
 
index c5923bc0641b7538fbe423929c691d691e838160..b95c23fb28b0ff9db3fc09a30defb22e89ab2fda 100644 (file)
@@ -54,3 +54,6 @@ void test6(void) {
    while (0);
 }
 
+int test7() {
+  return 4     // expected-error {{expected ';' after return statement}}
+}