[cfe-commits] r66027 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDecl.cpp test/Sema/function.c
Eli Friedman
eli.friedman at gmail.com
Tue Mar 3 23:31:01 PST 2009
Author: efriedma
Date: Wed Mar 4 01:30:59 2009
New Revision: 66027
URL: http://llvm.org/viewvc/llvm-project?rev=66027&view=rev
Log:
Check that the return type for function definitions is complete.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/function.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=66027&r1=66026&r2=66027&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Wed Mar 4 01:30:59 2009
@@ -798,6 +798,8 @@
"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,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66027&r1=66026&r2=66027&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 4 01:30:59 2009
@@ -2453,6 +2453,14 @@
}
}
+ // 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
Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=66027&r1=66026&r2=66027&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Wed Mar 4 01:30:59 2009
@@ -58,3 +58,5 @@
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}}
More information about the cfe-commits
mailing list