[cfe-commits] r93164 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/Sema/declspec.c test/Sema/invalid-decl.c

Douglas Gregor dgregor at apple.com
Mon Jan 11 10:46:22 PST 2010


Author: dgregor
Date: Mon Jan 11 12:46:21 2010
New Revision: 93164

URL: http://llvm.org/viewvc/llvm-project?rev=93164&view=rev
Log:
Tighten up the "cannot return array or function type" diagnostic to
say either "array type" or "function type", whichever it is. No reason
to make the user guess.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/declspec.c
    cfe/trunk/test/Sema/invalid-decl.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=93164&r1=93163&r2=93164&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 11 12:46:21 2010
@@ -1484,7 +1484,7 @@
   "jump bypasses setup of __block variable">;
 
 def err_func_returning_array_function : Error<
-  "function cannot return array or function type %0">;
+  "function cannot return %select{array|function}0 type %1">;
 def err_field_declared_as_function : Error<"field %0 declared as a function">;
 def err_field_incomplete : Error<"field has incomplete type %0">;
 def ext_variable_sized_type_in_struct : ExtWarn<

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=93164&r1=93163&r2=93164&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jan 11 12:46:21 2010
@@ -743,7 +743,8 @@
                                  bool Variadic, unsigned Quals,
                                  SourceLocation Loc, DeclarationName Entity) {
   if (T->isArrayType() || T->isFunctionType()) {
-    Diag(Loc, diag::err_func_returning_array_function) << T;
+    Diag(Loc, diag::err_func_returning_array_function) 
+      << T->isFunctionType() << T;
     return QualType();
   }
 
@@ -1045,9 +1046,11 @@
       const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
 
       // C99 6.7.5.3p1: The return type may not be a function or array type.
+      // For conversion functions, we'll diagnose this particular error later.
       if ((T->isArrayType() || T->isFunctionType()) &&
           (D.getName().getKind() != UnqualifiedId::IK_ConversionFunctionId)) {
-        Diag(DeclType.Loc, diag::err_func_returning_array_function) << T;
+        Diag(DeclType.Loc, diag::err_func_returning_array_function) 
+          << T->isFunctionType() << T;
         T = Context.IntTy;
         D.setInvalidType(true);
       }

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

==============================================================================
--- cfe/trunk/test/Sema/declspec.c (original)
+++ cfe/trunk/test/Sema/declspec.c Mon Jan 11 12:46:21 2010
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
 typedef char T[4];
 
-T foo(int n, int m) {  }  // expected-error {{cannot return array or function}}
+T foo(int n, int m) {  }  // expected-error {{cannot return array type}}
 
 void foof(const char *, ...) __attribute__((__format__(__printf__, 1, 2))), barf (void);
 

Modified: cfe/trunk/test/Sema/invalid-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-decl.c?rev=93164&r1=93163&r2=93164&view=diff

==============================================================================
--- cfe/trunk/test/Sema/invalid-decl.c (original)
+++ cfe/trunk/test/Sema/invalid-decl.c Mon Jan 11 12:46:21 2010
@@ -6,7 +6,7 @@
 
 
 // PR2400
-typedef xtype (*x)(void* handle); // expected-error {{function cannot return array or function type}} expected-warning {{type specifier missing, defaults to 'int'}} expected-warning {{type specifier missing, defaults to 'int'}}
+typedef xtype (*x)(void* handle); // expected-error {{function cannot return function type}} expected-warning {{type specifier missing, defaults to 'int'}} expected-warning {{type specifier missing, defaults to 'int'}}
 
 typedef void ytype();
 





More information about the cfe-commits mailing list