public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR c++/81119] Wshadow regression
@ 2017-06-19 14:15 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2017-06-19 14:15 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

This fixes pr 81119.  My rewriting of name lookup was a little too eager 
to warn about constructor hiding.  This restores the earlier behaviour 
of only warning when hiding via a function.

nathan
-- 
Nathan Sidwell

[-- Attachment #2: pr81119.diff --]
[-- Type: text/x-patch, Size: 2053 bytes --]

2017-06-19  Nathan Sidwell  <nathan@acm.org>

	PR c++/81119
	* name-lookup.c (update_binding): Only warn about constructors
	hidden by functions.

	PR c++/81119
	* g++.dg/warn/pr81119.C: New.

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 249364)
+++ cp/name-lookup.c	(working copy)
@@ -1784,6 +1784,14 @@ update_binding (cp_binding_level *level,
       else
 	goto conflict;
 
+      if (to_type != old_type
+	  && warn_shadow
+	  && MAYBE_CLASS_TYPE_P (TREE_TYPE (to_type))
+	  && !(DECL_IN_SYSTEM_HEADER (decl)
+	       && DECL_IN_SYSTEM_HEADER (to_type)))
+	warning (OPT_Wshadow, "%q#D hides constructor for %q#D",
+		 decl, to_type);
+
       to_val = ovl_insert (decl, old);
     }
   else if (!old)
@@ -1849,21 +1857,6 @@ update_binding (cp_binding_level *level,
 	  add_decl_to_level (level, to_add);
 	}
 
-      if (to_type != old_type)
-	{
-	  gcc_checking_assert (!old_type
-			       && TREE_CODE (to_type) == TYPE_DECL
-			       && DECL_ARTIFICIAL (to_type));
-
-	  tree type = TREE_TYPE (to_type);
-	  if (to_type != decl
-	      && MAYBE_CLASS_TYPE_P (type) && warn_shadow
-	      && (!DECL_IN_SYSTEM_HEADER (decl)
-		  || !DECL_IN_SYSTEM_HEADER (to_type)))
-	    warning (OPT_Wshadow, "%q#D hides constructor for %q#T",
-		     decl, type);
-	}
-
       if (slot)
 	{
 	  if (STAT_HACK_P (*slot))
Index: testsuite/g++.dg/warn/pr81119.C
===================================================================
--- testsuite/g++.dg/warn/pr81119.C	(nonexistent)
+++ testsuite/g++.dg/warn/pr81119.C	(working copy)
@@ -0,0 +1,20 @@
+// PR c++/81119 Wshadow regression
+// { dg-additional-options "-Wshadow" }
+
+struct A;
+typedef A A; // No warning, does not hide
+
+struct B; // { dg-message "previous" }
+typedef int B; // { dg-error "conflicting" }
+
+struct C;
+void C (); // { dg-warning "hides constructor" }
+void C (int); // warning not repeated
+
+struct D;
+int D; // no warning, not a function
+
+struct E;
+
+enum X 
+  {E}; // no warning, not a function

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-19 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 14:15 [PR c++/81119] Wshadow regression Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).