]> granicus.if.org Git - clang/commitdiff
Check that the return type for function definitions is complete.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 4 Mar 2009 07:30:59 +0000 (07:30 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 4 Mar 2009 07:30:59 +0000 (07:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66027 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaDecl.cpp
test/Sema/function.c

index a691a1f7026325d474160a56a5a243278f0068f0..5fb7fe2b299be6e2977a87824ac2ea012be5ce7c 100644 (file)
@@ -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,
index 3880792516909bbcfc7b7a664055d128e7f0cd4b..e1b27c64a4db1519e3e4e47659de5804a5f30806 100644 (file)
@@ -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
index a1d7137796045b26eec86476ac7d58799ffb57bf..90ade3380b942b1ce4585898672cf56569e47fb4 100644 (file)
@@ -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}}