This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/39763
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Apr 2009 13:04:09 -0400
- Subject: C++ PATCH for c++/39763
My patch for 39526 fixed the warning for shadowing a parm, but not the
warning for shadowing another local. Oops.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.4.
2009-04-14 Jason Merrill <jason@redhat.com>
PR c++/39763
* name-lookup.c (pushdecl_maybe_friend): Avoid all warnings
about shadowing by tentative parms.
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 2eebb79..b47c0c5 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1008,13 +1008,18 @@ pushdecl_maybe_friend (tree x, bool is_friend)
&& TREE_PUBLIC (x))
TREE_PUBLIC (name) = 1;
+ /* Don't complain about the parms we push and then pop
+ while tentatively parsing a function declarator. */
+ if (TREE_CODE (x) == PARM_DECL && DECL_CONTEXT (x) == NULL_TREE)
+ /* Ignore. */;
+
/* Warn if shadowing an argument at the top level of the body. */
- if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
- /* Inline decls shadow nothing. */
- && !DECL_FROM_INLINE (x)
- && TREE_CODE (oldlocal) == PARM_DECL
- /* Don't check the `this' parameter. */
- && !DECL_ARTIFICIAL (oldlocal))
+ else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
+ /* Inline decls shadow nothing. */
+ && !DECL_FROM_INLINE (x)
+ && TREE_CODE (oldlocal) == PARM_DECL
+ /* Don't check the `this' parameter. */
+ && !DECL_ARTIFICIAL (oldlocal))
{
bool err = false;
@@ -1038,10 +1043,7 @@ pushdecl_maybe_friend (tree x, bool is_friend)
}
}
- if (warn_shadow && !err
- /* Don't complain about the parms we push and then pop
- while tentatively parsing a function declarator. */
- && !(TREE_CODE (x) == PARM_DECL && DECL_CONTEXT (x) == NULL_TREE))
+ if (warn_shadow && !err)
{
warning (OPT_Wshadow, "declaration of %q#D shadows a parameter", x);
warning (OPT_Wshadow, "%Jshadowed declaration is here", oldlocal);
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-4.C b/gcc/testsuite/g++.dg/warn/Wshadow-4.C
index 16399b2..2238653 100644
--- a/gcc/testsuite/g++.dg/warn/Wshadow-4.C
+++ b/gcc/testsuite/g++.dg/warn/Wshadow-4.C
@@ -18,3 +18,15 @@ int foo(int infoo) // { dg-warning "shadowed declaration" }
};
return outfoo;
}
+
+// PR c++/39763
+int foo2(void)
+{
+ int infoo = 0; // { dg-warning "shadowed declaration" }
+ int outfoo( INetURLObject( infoo ).GetMainURL()); // { dg-bogus "shadows" }
+ struct A
+ {
+ void f(int infoo) { } // { dg-warning "shadows a previous local" }
+ };
+ return outfoo;
+}