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

Richard Trieu rtrieu at google.com
Fri Jan 20 18:59:18 PST 2012


Author: rtrieu
Date: Fri Jan 20 20:59:18 2012
New Revision: 148621

URL: http://llvm.org/viewvc/llvm-project?rev=148621&view=rev
Log:
Fix code so that a SkipUntil will ignore semicolons when skipping a
function body.  This keeps the brace count accurate to prevent
additional errors.  Also, moved the caret from the brace to the function
name.

Code:
class F{ int Foo{ return 1; } };

Fixed error:
parameters.cc:1:14: error: function definition does not declare parameters
class F{ int Foo{ return 1; } };
             ^
1 error generated.

Old errors:
parameters.cc:1:17: error: function definition does not declare parameters
class F{ int Foo{ return 1; } };
                ^
parameters.cc:1:30: error: expected ';' after class
class F{ int Foo{ return 1; } };
                             ^
                             ;
parameters.cc:1:31: error: expected external declaration
class F{ int Foo{ return 1; } };
                              ^
3 errors generated.



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

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=148621&r1=148620&r2=148621&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Jan 20 20:59:18 2012
@@ -1849,9 +1849,9 @@
 
     if (DefinitionKind) {
       if (!DeclaratorInfo.isFunctionDeclarator()) {
-        Diag(Tok, diag::err_func_def_no_params);
+        Diag(DeclaratorInfo.getIdentifierLoc(), diag::err_func_def_no_params);
         ConsumeBrace();
-        SkipUntil(tok::r_brace, true);
+        SkipUntil(tok::r_brace, /*StopAtSemi*/false);
         
         // Consume the optional ';'
         if (Tok.is(tok::semi))
@@ -1860,12 +1860,13 @@
       }
 
       if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-        Diag(Tok, diag::err_function_declared_typedef);
+        Diag(DeclaratorInfo.getIdentifierLoc(),
+             diag::err_function_declared_typedef);
         // This recovery skips the entire function body. It would be nice
         // to simply call ParseCXXInlineMethodDef() below, however Sema
         // assumes the declarator represents a function, not a typedef.
         ConsumeBrace();
-        SkipUntil(tok::r_brace, true);
+        SkipUntil(tok::r_brace, /*StopAtSemi*/false);
 
         // Consume the optional ';'
         if (Tok.is(tok::semi))

Modified: cfe/trunk/test/Parser/cxx-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-class.cpp?rev=148621&r1=148620&r2=148621&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-class.cpp (original)
+++ cfe/trunk/test/Parser/cxx-class.cpp Fri Jan 20 20:59:18 2012
@@ -54,6 +54,13 @@
   int i;
 };
 
+class F {
+    int F1 { return 1; } // expected-error{{function definition does not declare parameters}}
+    void F2 {} // expected-error{{function definition does not declare parameters}}
+    typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
+    typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
+};
+
 // PR11109 must appear at the end of the source file
 class pr11109r3 { // expected-note{{to match this '{'}}
   public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}





More information about the cfe-commits mailing list