[cfe-commits] r95038 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/Parser/declarators.c

Chris Lattner sabre at nondot.org
Mon Feb 1 16:37:27 PST 2010


Author: lattner
Date: Mon Feb  1 18:37:27 2010
New Revision: 95038

URL: http://llvm.org/viewvc/llvm-project?rev=95038&view=rev
Log:
improve diagnostics on missing ; in a struct.  Before:

t.c:4:3: error: expected ';' at end of declaration list
  int y;
  ^
t.c:4:8: warning: extra ';' inside a struct or union
  int y;
       ^
t.c:6:1: warning: expected ';' at end of declaration list
};
^

After:

t.c:3:8: error: expected ';' at end of declaration list
  int x  // expected-error {{expected ';' at end of declaration list}}
       ^
       ;
t.c:5:8: warning: expected ';' at end of declaration list
  int z
       ^
       ;


Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/declarators.c

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=95038&r1=95037&r2=95038&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Feb  1 18:37:27 2010
@@ -1750,14 +1750,14 @@
       ConsumeToken();
       if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
         Diag(Tok, diag::err_unexpected_at);
-        SkipUntil(tok::semi, true, true);
+        SkipUntil(tok::semi, true);
         continue;
       }
       ConsumeToken();
       ExpectAndConsume(tok::l_paren, diag::err_expected_lparen);
       if (!Tok.is(tok::identifier)) {
         Diag(Tok, diag::err_expected_ident);
-        SkipUntil(tok::semi, true, true);
+        SkipUntil(tok::semi, true);
         continue;
       }
       llvm::SmallVector<DeclPtrTy, 16> Fields;
@@ -1771,12 +1771,14 @@
     if (Tok.is(tok::semi)) {
       ConsumeToken();
     } else if (Tok.is(tok::r_brace)) {
-      Diag(Tok, diag::ext_expected_semi_decl_list);
+      ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
       break;
     } else {
-      Diag(Tok, diag::err_expected_semi_decl_list);
-      // Skip to end of block or statement
+      ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
+      // Skip to end of block or statement to avoid ext-warning on extra ';'.
       SkipUntil(tok::r_brace, true, true);
+      // If we stopped at a ';', eat it.
+      if (Tok.is(tok::semi)) ConsumeToken();
     }
   }
 

Modified: cfe/trunk/test/Parser/declarators.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/declarators.c?rev=95038&r1=95037&r2=95038&view=diff

==============================================================================
--- cfe/trunk/test/Parser/declarators.c (original)
+++ cfe/trunk/test/Parser/declarators.c Mon Feb  1 18:37:27 2010
@@ -64,3 +64,10 @@
 static g = 4;  // expected-warning {{type specifier missing, defaults to 'int'}}
 static h        // expected-warning {{type specifier missing, defaults to 'int'}} 
       __asm__("foo");
+
+
+struct test9 {
+  int x  // expected-error {{expected ';' at end of declaration list}}
+  int y;
+  int z  // expected-warning {{expected ';' at end of declaration list}}
+};





More information about the cfe-commits mailing list