[cfe-commits] r46603 - in /cfe/trunk: Parse/ParseDecl.cpp include/clang/Basic/DiagnosticKinds.def test/Parser/declarators.c

Chris Lattner sabre at nondot.org
Wed Jan 30 22:10:07 PST 2008


Author: lattner
Date: Thu Jan 31 00:10:07 2008
New Revision: 46603

URL: http://llvm.org/viewvc/llvm-project?rev=46603&view=rev
Log:
Fix PR1965: missing diagnostics for parameters that are missing
type specifiers.  This required updating some (buggy) tests, and the
testcase was previously accidentally committed.


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

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

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Thu Jan 31 00:10:07 2008
@@ -1350,6 +1350,20 @@
              ParmII->getName());
         ParmII = 0;
       }
+
+      // If no parameter was specified, verify that *something* was specified,
+      // otherwise we have a missing type and identifier.
+      if (!DS.hasTypeSpecifier()) {
+        if (ParmII)
+          Diag(ParmDecl.getIdentifierLoc(),
+               diag::err_param_requires_type_specifier, ParmII->getName());
+        else
+          Diag(Tok.getLocation(), diag::err_anon_param_requires_type_specifier);
+          
+        // Default the parameter to 'int'.
+        const char *PrevSpec = 0;
+        DS.SetTypeSpecType(DeclSpec::TST_int, Tok.getLocation(), PrevSpec);
+      }
         
       ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 
         ParmDecl.getIdentifierLoc(), ParamTy.Val, ParmDecl.getInvalidType(),

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Jan 31 00:10:07 2008
@@ -542,6 +542,11 @@
      "variable length arrays are a C99 feature, accepted as an extension")
 DIAG(err_invalid_storage_class_in_func_decl, ERROR,
      "invalid storage class specifier in function declarator")
+DIAG(err_anon_param_requires_type_specifier, ERROR,
+     "type specifier required for unnamed parameter")
+DIAG(err_param_requires_type_specifier, ERROR,
+     "type specifier required for parameter '%0'")
+
 DIAG(err_invalid_reference_qualifier_application, ERROR,
      "'%0' qualifier may not be applied to a reference")
 DIAG(err_declarator_need_ident, ERROR,

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

==============================================================================
--- cfe/trunk/test/Parser/declarators.c (original)
+++ cfe/trunk/test/Parser/declarators.c Thu Jan 31 00:10:07 2008
@@ -6,7 +6,7 @@
 void f1(int [*]);
 void f2(int [const *]);
 void f3(int [volatile const*]);
-int f4(*XX)(void); /* expected-error {{cannot return}} */
+int f4(*XX)(void); /* expected-error {{cannot return}} expected-error {{type specifier required}} */
 
 char ((((*X))));
 





More information about the cfe-commits mailing list