]> granicus.if.org Git - clang/commitdiff
Fix PR1965: missing diagnostics for parameters that are missing
authorChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2008 06:10:07 +0000 (06:10 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2008 06:10:07 +0000 (06:10 +0000)
type specifiers.  This required updating some (buggy) tests, and the
testcase was previously accidentally committed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46603 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseDecl.cpp
include/clang/Basic/DiagnosticKinds.def
test/Parser/declarators.c

index 003554fbaa9696060e08e3552ec00b7d06edf1e6..91e77b95e09847b90cb17824fd2bce41aea8cb4e 100644 (file)
@@ -1350,6 +1350,20 @@ void Parser::ParseParenDeclarator(Declarator &D) {
              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(),
index 78f6c61c51200fb76d30ac65df2cf11406cf1d22..02d3159c6ad572b1067e95a85f5570d8ca6d5c6c 100644 (file)
@@ -542,6 +542,11 @@ DIAG(ext_vla, EXTENSION,
      "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,
index 91cd81653bf7c789b48c731165ef1ef0f082d1ee..e00035c8e0fca1241bfa552d46d8e7cee8faa82d 100644 (file)
@@ -6,7 +6,7 @@ void f0();
 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))));