summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.def2
-rw-r--r--clang/lib/Sema/SemaDecl.cpp8
-rw-r--r--clang/test/Sema/function.c2
3 files changed, 12 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.def b/clang/include/clang/Basic/DiagnosticSemaKinds.def
index a691a1f7026..5fb7fe2b299 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/clang/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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 38807925169..e1b27c64a4d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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/clang/test/Sema/function.c b/clang/test/Sema/function.c
index a1d71377960..90ade3380b9 100644
--- a/clang/test/Sema/function.c
+++ b/clang/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}}
OpenPOWER on IntegriCloud