From cd8812948bc8a65dcf10c541c1775e5ba44def6c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 19 Dec 2007 05:31:29 +0000 Subject: [PATCH] Implement C99 6.7.5.3p1 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45188 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaType.cpp | 9 +++++++++ include/clang/Basic/DiagnosticKinds.def | 2 ++ test/Sema/declspec.c | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 test/Sema/declspec.c diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 8a5cfaa7db..fa9c9ed681 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -262,6 +262,15 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { // does not have a K&R-style identifier list), then the arguments are part // of the type, otherwise the argument list is (). const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; + + // C99 6.7.5.3p1: The return type may not be a function or array type. + if (T->isArrayType() || T->isFunctionType()) { + Diag(DeclType.Loc, diag::err_func_returning_array_function, + T.getAsString()); + T = Context.IntTy; + D.setInvalidType(true); + } + if (!FTI.hasPrototype) { // Simple void foo(), where the incoming T is the result type. T = Context.getFunctionTypeNoProto(T); diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 811576e9e7..264024b2d9 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -644,6 +644,8 @@ DIAG(warn_implicit_function_decl, WARNING, DIAG(ext_implicit_function_decl, EXTENSION, "implicit declaration of function '%0' is invalid in C99") +DIAG(err_func_returning_array_function, ERROR, + "function cannot return array or function type '%0'") DIAG(err_field_declared_as_function, ERROR, "field '%0' declared as a function") DIAG(err_field_incomplete, ERROR, diff --git a/test/Sema/declspec.c b/test/Sema/declspec.c new file mode 100644 index 0000000000..d9e02ec42e --- /dev/null +++ b/test/Sema/declspec.c @@ -0,0 +1,5 @@ +// RUN: clang %s -verify -fsyntax-only +typedef char T[4]; + +T foo(int n, int m) { } // expected-error {{cannot return array or function}} + -- 2.40.0