Implement C99 6.7.5.3p1

llvm-svn: 45188
This commit is contained in:
Chris Lattner 2007-12-19 05:31:29 +00:00
parent 747359f973
commit ea72f449fe
3 changed files with 16 additions and 0 deletions

View File

@ -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 // does not have a K&R-style identifier list), then the arguments are part
// of the type, otherwise the argument list is (). // of the type, otherwise the argument list is ().
const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; 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) { if (!FTI.hasPrototype) {
// Simple void foo(), where the incoming T is the result type. // Simple void foo(), where the incoming T is the result type.
T = Context.getFunctionTypeNoProto(T); T = Context.getFunctionTypeNoProto(T);

View File

@ -644,6 +644,8 @@ DIAG(warn_implicit_function_decl, WARNING,
DIAG(ext_implicit_function_decl, EXTENSION, DIAG(ext_implicit_function_decl, EXTENSION,
"implicit declaration of function '%0' is invalid in C99") "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, DIAG(err_field_declared_as_function, ERROR,
"field '%0' declared as a function") "field '%0' declared as a function")
DIAG(err_field_incomplete, ERROR, DIAG(err_field_incomplete, ERROR,

View File

@ -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}}