[Bug c++/57709] -Wshadow is too strict / has false positives
manu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 19 06:31:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57709
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic, patch
Target|x86_64-unknown-linux-gnu |
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-11-19
Ever confirmed|0 |1
--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
The following patch compiles and gives the following output:
/home/manuel/t.cc:6:18: warning: declaration of ‘both_var’ shadows a member of
‘C’ [-Wshadow]
void m() { int both_var, var_and_method; }
^
/home/manuel/t.cc:3:7: note: shadowed declaration is here
int both_var;
^
No other testing besides that. Please feel free to take it from here.
Index: name-lookup.c
===================================================================
--- name-lookup.c (revision 205004)
+++ name-lookup.c (working copy)
@@ -1216,13 +1216,25 @@ pushdecl_maybe_friend_1 (tree x, bool is
else
member = NULL_TREE;
if (member && !TREE_STATIC (member))
{
- /* Location of previous decl is not useful in this case. */
- warning (OPT_Wshadow, "declaration of %qD shadows a member of
'this'",
- x);
+ if (BASELINK_P (member))
+ member = BASELINK_FUNCTIONS (member);
+
+ /* Do not warn if a variable shadows a function, unless
+ the variable is a function or a pointer-to-function. */
+ if (!(TREE_CODE (member) == METHOD_TYPE
+ && TREE_CODE (x) != FUNCTION_DECL
+ && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (x)))) {
+ if (warning_at (input_location,
+ OPT_Wshadow, "declaration of %qD shadows a
member of %qT",
+ x, current_nonlambda_class_type ())
+ && DECL_P(member))
+ inform (DECL_SOURCE_LOCATION (member),
+ "shadowed declaration is here");
+ }
}
else if (oldglobal != NULL_TREE
&& (VAR_P (oldglobal)
/* If the old decl is a type decl, only warn if the
old decl is an explicit typedef or if both the
More information about the Gcc-bugs
mailing list