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

Chris Lattner sabre at nondot.org
Sun Feb 10 15:08:00 PST 2008


Author: lattner
Date: Sun Feb 10 17:08:00 2008
New Revision: 46938

URL: http://llvm.org/viewvc/llvm-project?rev=46938&view=rev
Log:
Fix PR1999, by emitting a hard error only if an argument declarator is completely 
missing.  Otherwise, it is an implicit int case, which is valid in c90 and invalid 
elsewhere, but accepted as an extension.

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

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

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Sun Feb 10 17:08:00 2008
@@ -1362,6 +1362,8 @@
         break;
       }
       
+      SourceLocation DSStart = Tok.getLocation();
+      
       // Parse the declaration-specifiers.
       DeclSpec DS;
       ParseDeclarationSpecifiers(DS);
@@ -1406,16 +1408,19 @@
 
       // If no parameter was specified, verify that *something* was specified,
       // otherwise we have a missing type and identifier.
-      if (!DS.hasTypeSpecifier()) {
+      if (DS.getParsedSpecifiers() == DeclSpec::PQ_None && 
+          ParmDecl.getIdentifier() == 0 && ParmDecl.getNumTypeObjects() == 0) {
+        Diag(DSStart, diag::err_missing_param);
+      } else if (!DS.hasTypeSpecifier() &&
+                 (getLang().C99 || getLang().CPlusPlus)) {
+        // Otherwise, if something was specified but a type specifier wasn't,
+        // (e.g. "x" or "restrict x" or "restrict"), this is a use of implicit
+        // int.  This is valid in C90, but not in C99 or C++.
         if (ParmII)
           Diag(ParmDecl.getIdentifierLoc(),
-               diag::err_param_requires_type_specifier, ParmII->getName());
+               diag::ext_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);
+          Diag(DSStart, diag::ext_anon_param_requires_type_specifier);
       }
         
       ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Feb 10 17:08:00 2008
@@ -540,10 +540,12 @@
      "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(ext_anon_param_requires_type_specifier, EXTENSION,
+     "type specifier required for unnamed parameter, defaults to int")
+DIAG(ext_param_requires_type_specifier, EXTENSION,
+     "type specifier required for parameter '%0', defaults to int")
+DIAG(err_missing_param, ERROR,
+     "expected parameter declarator")
 
 DIAG(err_invalid_reference_qualifier_application, ERROR,
      "'%0' qualifier may not be applied to a reference")

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

==============================================================================
--- cfe/trunk/test/Parser/declarators.c (original)
+++ cfe/trunk/test/Parser/declarators.c Sun Feb 10 17:08:00 2008
@@ -1,4 +1,4 @@
-// RUN: clang %s -fsyntax-only -verify
+// RUN: clang %s -fsyntax-only -verify -pedantic
 
 extern int a1[];
 
@@ -6,7 +6,7 @@
 void f1(int [*]);
 void f2(int [const *]);
 void f3(int [volatile const*]);
-int f4(*XX)(void); /* expected-error {{cannot return}} expected-error {{type specifier required}} */
+int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier required}} */
 
 char ((((*X))));
 

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

==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Sun Feb 10 17:08:00 2008
@@ -27,3 +27,6 @@
 
 int test4 = 0LL;		/* expected-warning {{long long}} */
 
+/* PR1999 */
+void test5(register);
+

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

==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Sun Feb 10 17:08:00 2008
@@ -1,4 +1,4 @@
-// RUN: clang %s -fsyntax-only -verify
+// RUN: clang %s -fsyntax-only -verify -pedantic
 // PR1892
 void f(double a[restrict][5]);  // should promote to restrict ptr.
 void f(double (* restrict a)[5]);
@@ -16,10 +16,10 @@
 
 // PR1965
 int t5(b);          // expected-error {{parameter list without types}}
-int t6(int x, g);   // expected-error {{type specifier required for parameter 'g'}}
+int t6(int x, g);   // expected-warning {{type specifier required for parameter 'g'}}
 
-int t7(, );       // expected-error {{type specifier required}} expected-error {{type specifier required}}
-int t8(, int a);  // expected-error {{type specifier required}}
-int t9(int a, );  // expected-error {{type specifier required}}
+int t7(, );       // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
+int t8(, int a);  // expected-error {{expected parameter declarator}}
+int t9(int a, );  // expected-error {{expected parameter declarator}}
 
 





More information about the cfe-commits mailing list