aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2005-02-03 02:21:10 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2005-02-03 02:21:10 +0000
commit73aea290cc5417e4025eb92d95afaf1eeab73631 (patch)
tree364e34ebace79fcfdc6374fb770c5ba7d7e4e33e /gcc
parent1f732f61ea2ac643e30b8068ee3f6737f07de271 (diff)
downloadgcc-73aea290cc5417e4025eb92d95afaf1eeab73631.zip
gcc-73aea290cc5417e4025eb92d95afaf1eeab73631.tar.gz
gcc-73aea290cc5417e4025eb92d95afaf1eeab73631.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/c-decl.c17
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/nested-func-3.c20
-rw-r--r--gcc/testsuite/gcc.dg/pr18596-3.c1
5 files changed, 53 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 31c8ea8..ee74a41 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index ad76f23..0b7b97e 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. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3e1fee4..1d80350 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.dg/nested-func-3.c b/gcc/testsuite/gcc.dg/nested-func-3.c
new file mode 100644
index 0000000..c4c016c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/nested-func-3.c
@@ -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);
+}
diff --git a/gcc/testsuite/gcc.dg/pr18596-3.c b/gcc/testsuite/gcc.dg/pr18596-3.c
index c2a04f8..74a6e63 100644
--- a/gcc/testsuite/gcc.dg/pr18596-3.c
+++ b/gcc/testsuite/gcc.dg/pr18596-3.c
@@ -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 };