[cfe-commits] r47103 - in /cfe/trunk: Parse/Parser.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/declspec.c

Steve Naroff snaroff at apple.com
Wed Feb 13 18:58:32 PST 2008


Author: snaroff
Date: Wed Feb 13 20:58:32 2008
New Revision: 47103

URL: http://llvm.org/viewvc/llvm-project?rev=47103&view=rev
Log:

A much better fix for http://llvm.org/bugs/show_bug.cgi?id=1987.

Modified:
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Sema/declspec.c

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=47103&r1=47102&r2=47103&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Wed Feb 13 20:58:32 2008
@@ -367,9 +367,6 @@
   // Parse the common declaration-specifiers piece.
   DeclSpec DS;
   ParseDeclarationSpecifiers(DS);
-  // If the decl specs are invalid, there is no need to continue.
-  if (DS.isInvalid())
-    return 0;
     
   // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
   // declaration-specifiers init-declarator-list[opt] ';'
@@ -422,6 +419,20 @@
   } else if (DeclaratorInfo.isFunctionDeclarator() &&
              (Tok.is(tok::l_brace) ||           // int X() {}
               isDeclarationSpecifier())) {      // int X(f) int f; {}
+    if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
+      Diag(Tok, diag::err_function_declared_typedef);
+      
+      if (Tok.is(tok::l_brace)) {
+        // This recovery skips the entire function body. It would be nice
+        // to simply call ParseFunctionDefintion() below, however Sema 
+        // assumes the declarator represents a function, not a typedef.
+        ConsumeBrace();
+        SkipUntil(tok::r_brace, true);
+      } else {
+        SkipUntil(tok::semi);
+      }
+      return 0;
+    }
     return ParseFunctionDefinition(DeclaratorInfo);
   } else {
     if (DeclaratorInfo.isFunctionDeclarator())

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=47103&r1=47102&r2=47103&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Feb 13 20:58:32 2008
@@ -352,6 +352,8 @@
      "expected ';' at end of declaration list")
 DIAG(ext_expected_semi_decl_list, EXTENSION,
      "expected ';' at end of declaration list")
+DIAG(err_function_declared_typedef, ERROR,
+     "function definition declared 'typedef'")
 DIAG(err_expected_fn_body, ERROR,
      "expected function body after function declarator")
 DIAG(err_expected_after_declarator, ERROR,

Modified: cfe/trunk/test/Sema/declspec.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/declspec.c?rev=47103&r1=47102&r2=47103&view=diff

==============================================================================
--- cfe/trunk/test/Sema/declspec.c (original)
+++ cfe/trunk/test/Sema/declspec.c Wed Feb 13 20:58:32 2008
@@ -5,8 +5,12 @@
 
 void foof(const char *, ...) __attribute__((__format__(__printf__, 1, 2))), barf (void);
 
+int typedef validTypeDecl() { } // expected-error {{function definition declared 'typedef'}}
+
 struct _zend_module_entry { }
 typedef struct _zend_function_entry { } // expected-error {{cannot combine with previous 'struct' declaration specifier}}
-static void buggy(int *x) { // expected-error {{cannot combine with previous 'typedef' declaration specifier}} \
-                            // expected-error {{cannot combine with previous 'struct' declaration specifier}}
-                            // expected-error {{expected '}'}}
+static void buggy(int *x) { } // expected-error {{function definition declared 'typedef'}} \
+                              // expected-error {{cannot combine with previous 'typedef' declaration specifier}} \
+                              // expected-error {{cannot combine with previous 'struct' declaration specifier}}
+
+





More information about the cfe-commits mailing list