]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2012-10-29 Manuel López-Ibáñez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Oct 2012 20:17:23 +0000 (20:17 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Oct 2012 20:17:23 +0000 (20:17 +0000)
PR c/53066
c/
* c-decl.c (warn_if_shadowing): Do not warn if a variable
shadows a function, unless the variable is a function or a
pointer-to-function.
gcc/
* tree.h (FUNCTION_POINTER_TYPE_P): New.
testsuite/
* gcc.dg/Wshadow-4.c: New.
* gcc.dg/Wshadow-4.h: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192963 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wshadow-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wshadow-4.h [new file with mode: 0644]
gcc/tree.h

index 0b2a3be3225220bf006c15ec1bc0483432446fd7..574a4743c38929ecc8065ba9189416c5fb5d4026 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-29  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53066
+       * tree.h (FUNCTION_POINTER_TYPE_P): New.
+
 2012-10-29  Alexandre Oliva <aoliva@redhat.com>
 
        PR debug/54693
index 89d89f7aca26cccdeafae129f2d05c7f09f5d67f..f44131b74a1b50597e4a149d09ce3b45b9f8055d 100644 (file)
@@ -1,3 +1,10 @@
+2012-10-29  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53066
+       * c-decl.c (warn_if_shadowing): Do not warn if a variable
+       shadows a function, unless the variable is a function or a
+       pointer-to-function.
+
 2012-10-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/54381
index 80867caa18387410545176931c638dcc32e47122..f03146690e1d67ea9f92c2c1e2e3c89b917d4821 100644 (file)
@@ -2561,8 +2561,18 @@ warn_if_shadowing (tree new_decl)
          warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
                   new_decl);
        else if (DECL_FILE_SCOPE_P (old_decl))
-         warning (OPT_Wshadow, "declaration of %q+D shadows a global "
-                  "declaration", new_decl);
+         {
+           /* Do not warn if a variable shadows a function, unless
+              the variable is a function or a pointer-to-function.  */
+           if (TREE_CODE (old_decl) == FUNCTION_DECL
+               && TREE_CODE (new_decl) != FUNCTION_DECL
+               && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
+               continue;
+
+           warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow, 
+                       "declaration of %qD shadows a global declaration",
+                       new_decl);
+         }
        else if (TREE_CODE (old_decl) == FUNCTION_DECL
                 && DECL_BUILT_IN (old_decl))
          {
index c6899df3c95a8f668fbf08aa7f833b90f132f8fb..49d6b9de345c344e5116a64a2f5d66ad3ff23d83 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-29  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53066
+       * gcc.dg/Wshadow-4.c: New.
+       * gcc.dg/Wshadow-4.h: New.
+
 2012-10-29  Alexandre Oliva <aoliva@redhat.com>
 
        PR debug/54693
diff --git a/gcc/testsuite/gcc.dg/Wshadow-4.c b/gcc/testsuite/gcc.dg/Wshadow-4.c
new file mode 100644 (file)
index 0000000..f3b986f
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-Wshadow -Wsystem-headers" } */
+
+#include "Wshadow-4.h"
+extern void index2 (void); /* { dg-message "declaration is here" } */
+
+void foo (double index1,
+         double index2)
+{
+}
+
+void foo1 (void)
+{
+  double index1;
+  double index2;
+}
+
+void foo2 (void)
+{
+  {
+    double index1;
+    double index2;
+  }
+}
+
+void foo3 (void)
+{
+  void (*index1)(void); /* { dg-warning "shadows" } */
+  void (*index2)(void); /* { dg-warning "shadows" } */
+}
+
+void foo4 (void)
+{
+  void index1(void) {}; /* { dg-warning "shadows" } */
+  void index2(void) {}; /* { dg-warning "shadows" } */
+}
+
+/* { dg-message "declaration is here" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.dg/Wshadow-4.h b/gcc/testsuite/gcc.dg/Wshadow-4.h
new file mode 100644 (file)
index 0000000..5a44ca4
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma GCC system_header
+extern void index1 (void);
+
index c6a5eab502437ced701559d1d0219d7b82f1a769..d921886c2eaf13b4b9fe917faa8747b91ad44ec5 100644 (file)
@@ -1066,6 +1066,10 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
 #define POINTER_TYPE_P(TYPE) \
   (TREE_CODE (TYPE) == POINTER_TYPE || TREE_CODE (TYPE) == REFERENCE_TYPE)
 
+/* Nonzero if TYPE represents a pointer to function.  */
+#define FUNCTION_POINTER_TYPE_P(TYPE) \
+  (POINTER_TYPE_P (TYPE) && TREE_CODE (TREE_TYPE (TYPE)) == FUNCTION_TYPE)
+
 /* Nonzero if this type is a complete type.  */
 #define COMPLETE_TYPE_P(NODE) (TYPE_SIZE (NODE) != NULL_TREE)