From 8e3eed089060f316d48729c25814d697ec25b336 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 14 Jun 2009 00:23:56 +0000 Subject: change ParseStatementOrDeclaration to emit the 'missing ;' with 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 ^ ; llvm-svn: 73315 --- clang/lib/Parse/ParseStmt.cpp | 6 +++++- clang/test/Parser/statements.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'clang') diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 8cdcd517cab..955f00d7a0b 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -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); } diff --git a/clang/test/Parser/statements.c b/clang/test/Parser/statements.c index c5923bc0641..b95c23fb28b 100644 --- a/clang/test/Parser/statements.c +++ b/clang/test/Parser/statements.c @@ -54,3 +54,6 @@ void test6(void) { while (0); } +int test7() { + return 4 // expected-error {{expected ';' after return statement}} +} -- cgit v1.2.1