This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH C] PR 36774 Don't warn missing prototype to nested functions if defined before first use


Hi
-Wmissing-prototype should not trigger nested functions if defined before first use. -Wmissing-declaration also have the same problem.
Only global def would be warn with no previous prototype or declaration if defined before first use, While the public_flag of nested function isn't be set to 0 before check the warn now. Move forward the check for nested function would solve this problem.


Tested on i686-pc-linux-gnu, double checked the test cases with -Wmissing-prototype and -Wmissing-declaration, and no regression.

Is it ok for 4.6?

Thanks
Pearly
gcc/
2010-04-02  Shujing Zhao  <pearly.zhao@oracle.com>

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

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

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

Index: c-decl.c
===================================================================
--- c-decl.c	(revision 157720)
+++ c-decl.c	(working copy)
@@ -7424,6 +7424,10 @@ start_function (struct c_declspecs *decl
      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);
@@ -7524,10 +7528,6 @@ start_function (struct c_declspecs *decl
      (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: testsuite/gcc.dg/pr36774-2.c
===================================================================
--- testsuite/gcc.dg/pr36774-2.c	(revision 0)
+++ testsuite/gcc.dg/pr36774-2.c	(revision 0)
@@ -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);
+}
Index: testsuite/gcc.dg/pr36774-1.c
===================================================================
--- testsuite/gcc.dg/pr36774-1.c	(revision 0)
+++ testsuite/gcc.dg/pr36774-1.c	(revision 0)
@@ -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);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]