Hi,
thus, in order to not warn -Wshadow at instantiation time, I figured out
the below. Tested x86_64-linux.
Note, I took the idea of allowing for current_instantiation ()->decl !=
current_function_decl from some code prepared by Dodji for
-Wunused-local-typedefs: I'm not 100% sure it's necessary here, but in
any case testcases *10.C and *11.C exercise that path (in general, we
don't seem to have many testcases involving this specific kind of
-Wshadow and templates, thus it cannot hurt, IMO)
Thanks!
Paolo.
////////////////////
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c (revision 221795)
+++ cp/name-lookup.c (working copy)
@@ -1277,7 +1277,10 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
old and new decls are type decls. */
|| (TREE_CODE (oldglobal) == TYPE_DECL
&& (!DECL_ARTIFICIAL (oldglobal)
- || TREE_CODE (x) == TYPE_DECL))))
+ || TREE_CODE (x) == TYPE_DECL)))
+ && (current_instantiation () == NULL
+ || (current_instantiation ()->decl
+ != current_function_decl)))
/* XXX shadow warnings in outer-more namespaces */
{
if (warning_at (input_location, OPT_Wshadow,
Index: testsuite/g++.dg/warn/Wshadow-10.C
===================================================================
--- testsuite/g++.dg/warn/Wshadow-10.C (revision 0)
+++ testsuite/g++.dg/warn/Wshadow-10.C (working copy)
@@ -0,0 +1,15 @@
+// PR c++/56100
+// { dg-options "-Wshadow" }
+
+struct bar
+{
+ template <typename T>
+ void baz () { int foo; }
+};
+
+int foo;
+
+int main ()
+{
+ bar ().baz <int> ();
+}
Index: testsuite/g++.dg/warn/Wshadow-11.C
===================================================================
--- testsuite/g++.dg/warn/Wshadow-11.C (revision 0)
+++ testsuite/g++.dg/warn/Wshadow-11.C (working copy)
@@ -0,0 +1,15 @@
+// PR c++/56100
+// { dg-options "-Wshadow" }
+
+int foo; // { dg-message "shadowed declaration" }
+
+struct bar
+{
+ template <typename T>
+ void baz () { int foo; } // { dg-warning "shadows a global" }
+};
+
+int main ()
+{
+ bar ().baz <int> ();
+}
Index: testsuite/g++.dg/warn/Wshadow-8.C
===================================================================
--- testsuite/g++.dg/warn/Wshadow-8.C (revision 0)
+++ testsuite/g++.dg/warn/Wshadow-8.C (working copy)
@@ -0,0 +1,15 @@
+// PR c++/56100
+// { dg-options "-Wshadow" }
+
+template <typename T>
+struct bar
+{
+ void baz () { int foo; }
+};
+
+int foo;
+
+int main ()
+{
+ bar <int> ().baz ();
+}
Index: testsuite/g++.dg/warn/Wshadow-9.C
===================================================================
--- testsuite/g++.dg/warn/Wshadow-9.C (revision 0)
+++ testsuite/g++.dg/warn/Wshadow-9.C (working copy)
@@ -0,0 +1,15 @@
+// PR c++/56100
+// { dg-options "-Wshadow" }
+
+int foo; // { dg-message "shadowed declaration" }
+
+template <typename T>
+struct bar
+{
+ void baz () { int foo; } // { dg-warning "shadows a global" }
+};
+
+int main ()
+{
+ bar <int> ().baz ();
+}