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
+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
+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
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))
{
+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
--- /dev/null
+/* { 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 } */
--- /dev/null
+#pragma GCC system_header
+extern void index1 (void);
+
#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)