summaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-03 02:21:10 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-03 02:21:10 +0000
commit8a1f0315c246ca27860bbd84533c5a3402e4b2d3 (patch)
tree364e34ebace79fcfdc6374fb770c5ba7d7e4e33e /gcc/c-decl.c
parent586a72223a38c9e5d6532b75e1219bc790140326 (diff)
downloadgcc-8a1f0315c246ca27860bbd84533c5a3402e4b2d3.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94645 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index ad76f235de9..0b7b97ede23 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -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. */