diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-01-11 18:46:21 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-01-11 18:46:21 +0000 |
| commit | bb91767b824cf1b78cb551c308ca51f8da4e4377 (patch) | |
| tree | 94f76f1e3fa924f1a0aaad8497412cbd7fdf0e3b | |
| parent | 0ef736fef25b2bb65c5ccb6ab920f52aeed84c56 (diff) | |
| download | bcm5719-llvm-bb91767b824cf1b78cb551c308ca51f8da4e4377.tar.gz bcm5719-llvm-bb91767b824cf1b78cb551c308ca51f8da4e4377.zip | |
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.
llvm-svn: 93164
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Sema/declspec.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/invalid-decl.c | 2 |
4 files changed, 8 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index da94a21452e..d7f1f2f9776 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 499160d11f4..2bddf9ecd60 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -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); } diff --git a/clang/test/Sema/declspec.c b/clang/test/Sema/declspec.c index 2cf49aa29da..5b119601603 100644 --- a/clang/test/Sema/declspec.c +++ b/clang/test/Sema/declspec.c @@ -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); diff --git a/clang/test/Sema/invalid-decl.c b/clang/test/Sema/invalid-decl.c index 7f471a15268..a5e7ad3b1ec 100644 --- a/clang/test/Sema/invalid-decl.c +++ b/clang/test/Sema/invalid-decl.c @@ -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(); |

