]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c/36774 (-Wmissing-prototypes triggers on nested functions)
authorShujing Zhao <pearly.zhao@oracle.com>
Mon, 12 Apr 2010 03:43:21 +0000 (03:43 +0000)
committerShujing Zhao <pzhao@gcc.gnu.org>
Mon, 12 Apr 2010 03:43:21 +0000 (03:43 +0000)
gcc/
2010-04-12  Shujing Zhao  <pearly.zhao@oracle.com>

        PR c/36774
        * c-decl.c (start_function): Move forward check for nested function.

gcc/testsuite/
2010-04-12  Shujing Zhao  <pearly.zhao@oracle.com>

        PR c/36774
        * gcc.dg/pr36774-1.c: New test.
        * gcc.dg/pr36774-2.c: New test.

From-SVN: r158214

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr36774-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr36774-2.c [new file with mode: 0644]

index c2bd0a9a728774f92d3315d5d286e91a6ec9bae5..66b45437841cce64a428a26c77cb2298384bfbe0 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-12  Shujing Zhao  <pearly.zhao@oracle.com>
+
+       PR c/36774
+       * c-decl.c (start_function): Move forward check for nested function.
+
 2010-04-11  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        * config/sh/sh-protos.h (sh_legitimize_reload_address): Declare.
index bc90fdd38ddf9e9c0f9d89ef339499002e5fb474..bf8555715b072ec92f91be31ccc444491f7e434d 100644 (file)
@@ -7443,6 +7443,10 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
   DECL_INITIAL (decl1) = error_mark_node;
 
+  /* A nested function is not global.  */
+  if (current_function_decl != 0)
+    TREE_PUBLIC (decl1) = 0;
+
   /* If this definition isn't a prototype and we had a prototype declaration
      before, copy the arg type info from that prototype.  */
   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
@@ -7543,10 +7547,6 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
      (This does not mean `static' in the C sense!)  */
   TREE_STATIC (decl1) = 1;
 
-  /* A nested function is not global.  */
-  if (current_function_decl != 0)
-    TREE_PUBLIC (decl1) = 0;
-
   /* This is the earliest point at which we might know the assembler
      name of the function.  Thus, if it's set before this, die horribly.  */
   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
index 24eebcfd877b725055221198f3787e676d26c817..d5cddd4cf345dba9175d6e452b9627cfe4c87b13 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-12  Shujing Zhao  <pearly.zhao@oracle.com>
+
+       PR c/36774
+       * gcc.dg/pr36774-1.c: New test.
+       * gcc.dg/pr36774-2.c: New test.
+
 2010-04-11  Kaushik Phatak  <kaushik.phatak@kpitcummins.com>
 
        * gcc.target/sh/rte-delay-slot.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr36774-1.c b/gcc/testsuite/gcc.dg/pr36774-1.c
new file mode 100644 (file)
index 0000000..10a5e5f
--- /dev/null
@@ -0,0 +1,9 @@
+/* Nested functions shouldn't produce warnings if defined before first use.
+   Bug 36774. Test with -Wmissing-prototypes. */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-prototypes" } */
+
+int foo(int a) { /* { dg-warning "no previous prototype" } */
+    int bar(int b) { return b; } /* { dg-bogus "no previous prototype" } */
+    return bar(a);
+}
diff --git a/gcc/testsuite/gcc.dg/pr36774-2.c b/gcc/testsuite/gcc.dg/pr36774-2.c
new file mode 100644 (file)
index 0000000..bf394c9
--- /dev/null
@@ -0,0 +1,9 @@
+/* Nested functions shouldn't produce warnings if defined before first use.
+   Bug 36774. Test with -Wmissing-declarations. */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-declarations" } */
+
+int foo(int a) { /* { dg-warning "no previous declaration" } */
+    int bar(int b) { return b; } /* { dg-bogus "no previous declaration" } */
+    return bar(a);
+}
This page took 0.105426 seconds and 5 git commands to generate.