[cfe-commits] r95039 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp test/Parser/cxx-decl.cpp

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


Author: lattner
Date: Mon Feb  1 18:43:15 2010
New Revision: 95039

URL: http://llvm.org/viewvc/llvm-project?rev=95039&view=rev
Log:
improve diagnostics for C++ struct ; issues.  Before:

t.cc:4:3: error: expected ';' at end of declaration list
  int y;
  ^
t.cc:6:1: error: expected ';' at end of declaration list
};
^

After:

t.cc:3:8: error: expected ';' at end of declaration list
  int x
       ^
       ;
t.cc:5:8: error: expected ';' at end of declaration list
  int z
       ^
       ;


Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/cxx-decl.cpp

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Feb  1 18:43:15 2010
@@ -1189,8 +1189,7 @@
     if (Tok.is(tok::kw_namespace)) {
       Diag(UsingLoc, diag::err_using_namespace_in_class);
       SkipUntil(tok::semi, true, true);
-    }
-    else {
+    } else {
       SourceLocation DeclEnd;
       // Otherwise, it must be using-declaration.
       ParseUsingDeclaration(Declarator::MemberContext, UsingLoc, DeclEnd, AS);
@@ -1371,19 +1370,16 @@
       ParseDeclarator(DeclaratorInfo);
   }
 
-  if (Tok.is(tok::semi)) {
-    ConsumeToken();
-    Actions.FinalizeDeclaratorGroup(CurScope, DS, DeclsInGroup.data(),
-                                    DeclsInGroup.size());
+  if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
+    // Skip to end of block or statement.
+    SkipUntil(tok::r_brace, true, true);
+    // If we stopped at a ';', eat it.
+    if (Tok.is(tok::semi)) ConsumeToken();
     return;
   }
 
-  Diag(Tok, diag::err_expected_semi_decl_list);
-  // Skip to end of block or statement
-  SkipUntil(tok::r_brace, true, true);
-  if (Tok.is(tok::semi))
-    ConsumeToken();
-  return;
+  Actions.FinalizeDeclaratorGroup(CurScope, DS, DeclsInGroup.data(),
+                                  DeclsInGroup.size());
 }
 
 /// ParseCXXMemberSpecification - Parse the class definition.

Modified: cfe/trunk/test/Parser/cxx-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-decl.cpp?rev=95039&r1=95038&r2=95039&view=diff

==============================================================================
--- cfe/trunk/test/Parser/cxx-decl.cpp (original)
+++ cfe/trunk/test/Parser/cxx-decl.cpp Mon Feb  1 18:43:15 2010
@@ -52,3 +52,9 @@
               (y:b)  // expected-error {{unexpected ':' in nested name specifier}}
               4) : 5;
 }
+
+struct test4 {
+  int x  // expected-error {{expected ';' at end of declaration list}}
+  int y;
+  int z  // expected-error {{expected ';' at end of declaration list}}
+};





More information about the cfe-commits mailing list