]> granicus.if.org Git - clang/commitdiff
Tighten up the "cannot return array or function type" diagnostic to
authorDouglas Gregor <dgregor@apple.com>
Mon, 11 Jan 2010 18:46:21 +0000 (18:46 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 11 Jan 2010 18:46:21 +0000 (18:46 +0000)
say either "array type" or "function type", whichever it is. No reason
to make the user guess.

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

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

index da94a21452ea075493e118d02a9811d1b8fde21e..d7f1f2f9776400ca78b622e4d4991d0f08b7f87c 100644 (file)
@@ -1484,7 +1484,7 @@ def note_protected_by___block : Note<
   "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<
index 499160d11f4110f477d674d4d76f39843e1a2cc5..2bddf9ecd608cd681fb2ebc3f3855c7f6a643d9d 100644 (file)
@@ -743,7 +743,8 @@ QualType Sema::BuildFunctionType(QualType T,
                                  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 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
       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);
       }
index 2cf49aa29da1c5fa0326840f82a8562647d9052e..5b1196016032ba5a763b6197699a653c4ae1d736 100644 (file)
@@ -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);
 
index 7f471a1526812606205fd992f01860ee88383f1c..a5e7ad3b1ec1dd62dd611add9437cd88496a6ce3 100644 (file)
@@ -6,7 +6,7 @@ void test() {
 
 
 // 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();