re PR c/17807 (No warning/error for undefined local function.)

PR c/17807
	* c-decl.c (undef_nested_function): New variable.
	(pop_scope): Diagnose undefined nested functions.
	(finish_function): Don't attempt cgraph processing or genericizing
	if current top-level function contained an undefined nested
	function.  Reset undef_nested_function at the end of a top-level
	function.

testsuite:
	* gcc.dg/nested-func-3.c: New test.
	* gcc.dg/pr18596-3.c: Expect error for undefined nested function.

From-SVN: r94645
This commit is contained in:
Joseph Myers 2005-02-03 02:21:10 +00:00 committed by Joseph Myers
parent 1f732f61ea
commit 73aea290cc
5 changed files with 53 additions and 1 deletions

View File

@ -1,3 +1,13 @@
2005-02-03 Joseph S. Myers <joseph@codesourcery.com>
PR c/17807
* c-decl.c (undef_nested_function): New variable.
(pop_scope): Diagnose undefined nested functions.
(finish_function): Don't attempt cgraph processing or genericizing
if current top-level function contained an undefined nested
function. Reset undef_nested_function at the end of a top-level
function.
2005-02-02 Zdenek Dvorak <dvorakz@suse.cz>
* tree.c (build_int_cst_type): Take sign of the value into account

View File

@ -149,6 +149,11 @@ static int warn_about_return_type;
static int current_extern_inline;
/* Nonzero when the current toplevel function contains a declaration
of a nested function which is never defined. */
static bool undef_nested_function;
/* True means global_bindings_p should return false even if the scope stack
says we are in file scope. */
bool c_override_global_bindings_to_false;
@ -759,6 +764,12 @@ pop_scope (void)
&& DECL_ABSTRACT_ORIGIN (p) != 0
&& DECL_ABSTRACT_ORIGIN (p) != p)
TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
if (!DECL_EXTERNAL (p)
&& DECL_INITIAL (p) == 0)
{
error ("%Jnested function %qD declared but never defined", p, p);
undef_nested_function = true;
}
goto common_symbol;
case VAR_DECL:
@ -6376,7 +6387,8 @@ finish_function (void)
until their parent function is genericized. Since finalizing
requires GENERIC, delay that as well. */
if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
&& !undef_nested_function)
{
if (!decl_function_context (fndecl))
{
@ -6402,6 +6414,9 @@ finish_function (void)
}
}
if (!decl_function_context (fndecl))
undef_nested_function = false;
/* We're leaving the context of this function, so zap cfun.
It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
tree_rest_of_compilation. */

View File

@ -1,3 +1,9 @@
2005-02-03 Joseph S. Myers <joseph@codesourcery.com>
PR c/17807
* gcc.dg/nested-func-3.c: New test.
* gcc.dg/pr18596-3.c: Expect error for undefined nested function.
2005-02-02 Janis Johnson <janis187@us.ibm.com>
* gcc.test-framework/gen_directive_tests: Generate tests for

View File

@ -0,0 +1,20 @@
/* Undefined nested function should be a error, whether or not the
function is called. Bug 17807. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "" } */
void
f (void)
{
auto int fn (int); /* { dg-error "error: nested function 'fn' declared but never defined" } */
auto int fn2 (int); /* { dg-error "error: nested function 'fn2' declared but never defined" } */
sizeof(fn(1));
}
void
h (void)
{
auto int hn (int); /* { dg-error "error: nested function 'hn' declared but never defined" } */
hn (1);
}

View File

@ -6,6 +6,7 @@ int foo ()
static g () = 0; /* { dg-error "invalid storage class" } */
static int f () = 1; /* { dg-error "invalid storage class" } */
auto int h () = 0; /* { dg-error "initialized like a variable" } */
/* { dg-error "declared but never defined" "nested" { target *-*-* } 8 } */
static int i () = { 0 }; /* { dg-error "invalid storage class" } */
static int j () = /* { dg-error "invalid storage class" } */
{ 0, 0.0 };