From 7f0f5dce3adcfce88d5c9a0ad0146a33c01a1e8f Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 4 Mar 2009 07:30:59 +0000 Subject: [PATCH] Check that the return type for function definitions is complete. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66027 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.def | 2 ++ lib/Sema/SemaDecl.cpp | 8 ++++++++ test/Sema/function.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index a691a1f702..5fb7fe2b29 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -798,6 +798,8 @@ DIAG(err_block_return_missing_expr, ERROR, "non-void block should return a value") DIAG(err_block_with_return_type_requires_args, ERROR, "block with explicit return type requires argument list") +DIAG(err_func_def_incomplete_result, ERROR, + "result type for function definition cannot be incomplete") // Expressions. DIAG(ext_sizeof_function_type, EXTENSION, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 3880792516..e1b27c64a4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2453,6 +2453,14 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { } } + // The return type of a function definition must be complete + // (C99 6.9.1p3) + if (FD->getResultType()->isIncompleteType() && + !FD->getResultType()->isVoidType()) { + Diag(FD->getLocation(), diag::err_func_def_incomplete_result) << FD; + FD->setInvalidDecl(); + } + PushDeclContext(FnBodyScope, FD); // Check the validity of our function parameters diff --git a/test/Sema/function.c b/test/Sema/function.c index a1d7137796..90ade3380b 100644 --- a/test/Sema/function.c +++ b/test/Sema/function.c @@ -58,3 +58,5 @@ void f1static() { static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}} register void f2register(int); // expected-error{{illegal storage class on function}} } + +struct incomplete_test a(void) {} // expected-error{{result type for function definition cannot be incomplete}}