re PR c++/81119 (-Wshadow warns on "typedef struct foo foo;")
authorNathan Sidwell <nathan@acm.org>
Mon, 19 Jun 2017 14:13:58 +0000 (14:13 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 19 Jun 2017 14:13:58 +0000 (14:13 +0000)
PR c++/81119
* name-lookup.c (update_binding): Only warn about constructors
hidden by functions.

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

From-SVN: r249369

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr81119.C [new file with mode: 0644]

index 465e7d9ffe6ec607845c6baa990e8052e6cc21bb..fece2d040da97b31d284449ea05e8fbfa265c0ee 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-19  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/81119
+       * name-lookup.c (update_binding): Only warn about constructors
+       hidden by functions.
+
 2017-06-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/60063 - -Wunused-local-typedefs and templates.
index 6ed164d46452621616975298b6246b98806fcde3..a337942d6ae118a202bd33b48eaa5292d7cc4e95 100644 (file)
@@ -1784,6 +1784,14 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot,
       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, cxx_binding *binding, tree *slot,
          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 26e527c7e153d1cf44f1cab870584ac723c6a7e7..c7729e819fc05112b823f0754d7f41f54192c7b0 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-19  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/81119
+       * g++.dg/warn/pr81119.C: New.
+
 2017-06-19  Martin Liska  <mliska@suse.cz>
 
        PR sanitizer/80879
diff --git a/gcc/testsuite/g++.dg/warn/pr81119.C b/gcc/testsuite/g++.dg/warn/pr81119.C
new file mode 100644 (file)
index 0000000..2f82236
--- /dev/null
@@ -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