re PR c/53066 (Wshadow should not warn for shadowing an extern function)

2012-10-29  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	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.

From-SVN: r192963
This commit is contained in:
Manuel López-Ibáñez 2012-10-29 20:17:23 +00:00
parent 36290bb4d5
commit 077d1abec1
7 changed files with 75 additions and 2 deletions

View 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

View 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

View 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))
{

View 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

View File

@ -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 } */

View File

@ -0,0 +1,3 @@
#pragma GCC system_header
extern void index1 (void);

View 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)