diff mbox

[C++,Patch/RFC] PR 56100

Message ID 551AD5E6.9010605@oracle.com
State New
Headers show

Commit Message

Paolo Carlini March 31, 2015, 5:14 p.m. UTC
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.

////////////////////

Comments

Jason Merrill March 31, 2015, 7:13 p.m. UTC | #1
On 03/31/2015 01:14 PM, Paolo Carlini wrote:
> Note, I took the idea of allowing for current_instantiation ()->decl !=
> current_function_decl from some code prepared by Dodji for
> -Wunused-local-typedefs

Let's make this a predicate function.

Jason
diff mbox

Patch

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 ();
+}