PR c++/91921 - stray warning with -Woverloaded-virtual.
authorMarek Polacek <polacek@redhat.com>
Sat, 28 Sep 2019 11:46:33 +0000 (11:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sat, 28 Sep 2019 11:46:33 +0000 (11:46 +0000)
* class.c (warn_hidden): Only emit the second part of
-Woverloaded-virtual if the first part was issued.  Use inform instead
warning_at.

* g++.dg/warn/Woverloaded-2.C: New.
* g++.dg/warn/Woverloaded-2.h: New.
* g++.dg/warn/pr61945.C: Turn dg-warning into dg-message.
* g++.old-deja/g++.mike/warn6.C: Likewise.
* g++.old-deja/g++.warn/virt1.C: Likewise.

From-SVN: r276249

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Woverloaded-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Woverloaded-2.h [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr61945.C
gcc/testsuite/g++.old-deja/g++.mike/warn6.C
gcc/testsuite/g++.old-deja/g++.warn/virt1.C

index 895ebd9e8fbb256767e6374b1bd00257648d8c2a..c30d704aa4ffb11fbc95890c2a541e6ad1a66a9b 100644 (file)
@@ -1,5 +1,10 @@
 2019-09-28  Marek Polacek  <polacek@redhat.com>
 
+       PR c++/91921 - stray warning with -Woverloaded-virtual.
+       * class.c (warn_hidden): Only emit the second part of
+       -Woverloaded-virtual if the first part was issued.  Use inform instead
+       warning_at.
+
        PR c++/91923 - failure-to-SFINAE with class type NTTP in C++17.
        * pt.c (invalid_nontype_parm_type_p): Only emit errors when
        tf_error.
index 59a3d1a04966554a0515c23e28575b782398227e..3838f765a1d143b3c8916e840e206ee94533bb98 100644 (file)
@@ -2914,12 +2914,12 @@ warn_hidden (tree t)
        FOR_EACH_VEC_ELT (base_fndecls, j, base_fndecl)
          if (base_fndecl)
            {
+             auto_diagnostic_group d;
              /* Here we know it is a hider, and no overrider exists.  */
-             warning_at (location_of (base_fndecl),
-                         OPT_Woverloaded_virtual,
-                         "%qD was hidden", base_fndecl);
-             warning_at (location_of (fns),
-                         OPT_Woverloaded_virtual, "  by %qD", fns);
+             if (warning_at (location_of (base_fndecl),
+                             OPT_Woverloaded_virtual,
+                             "%qD was hidden", base_fndecl))
+               inform (location_of (fns), "  by %qD", fns);
            }
       }
 }
index 617fc99715f8574354d9c192fa33a5f934d85a5b..104a83be28a79e91c0470c75d5bda21499dc4d1a 100644 (file)
@@ -1,5 +1,12 @@
 2019-09-28  Marek Polacek  <polacek@redhat.com>
 
+       PR c++/91921 - stray warning with -Woverloaded-virtual.
+       * g++.dg/warn/Woverloaded-2.C: New.
+       * g++.dg/warn/Woverloaded-2.h: New.
+       * g++.dg/warn/pr61945.C: Turn dg-warning into dg-message.
+       * g++.old-deja/g++.mike/warn6.C: Likewise.
+       * g++.old-deja/g++.warn/virt1.C: Likewise.
+
        PR c++/91923 - failure-to-SFINAE with class type NTTP in C++17.
        * g++.dg/cpp0x/nontype5.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/warn/Woverloaded-2.C b/gcc/testsuite/g++.dg/warn/Woverloaded-2.C
new file mode 100644 (file)
index 0000000..84d65de
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/91921 - stray warning with -Woverloaded-virtual.
+// { dg-options "-Woverloaded-virtual" }
+
+#include "Woverloaded-2.h"
+
+struct B : A
+{
+  void f(int);
+};
diff --git a/gcc/testsuite/g++.dg/warn/Woverloaded-2.h b/gcc/testsuite/g++.dg/warn/Woverloaded-2.h
new file mode 100644 (file)
index 0000000..b9e15b0
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma GCC system_header
+
+struct A
+{
+  virtual void f();
+};
index 5584d841692fdacf2ea4a9bca725af686c206f44..3d40581e5e359fd0e6d94a64a43984f675f987b4 100644 (file)
@@ -7,5 +7,5 @@ class A {
 };
 class B : A {
   template <typename>
-  void foo ();         // { dg-warning "by .B::foo\\(\\)." }
+  void foo ();         // { dg-message "by .B::foo\\(\\)." }
 };
index 9c694d62559857014a2e6504b1f2bbe21d351b1f..26759cfb527545690ae358b77d605035a927449f 100644 (file)
@@ -30,13 +30,13 @@ struct D : public B, public B2, public B3 {
 
   virtual void bothsame(int);
 
-  virtual void bothdiff(int);          // { dg-warning "" } 
+  virtual void bothdiff(int);          // { dg-message "" } 
 
   virtual void both2same(int);
   virtual void both2same(float);
 
-  virtual void both12diff(int);                // { dg-warning "" } 
+  virtual void both12diff(int);                // { dg-message "" } 
 
-  virtual void bothfardiff(int);       // { dg-warning "" } 
+  virtual void bothfardiff(int);       // { dg-message "" } 
 };
 
index 4550dd5e0547901eb25cf66ca54970dfd0c23201..c68de8a7e7c1cee9686ffdc2171b16ba9e39799c 100644 (file)
@@ -6,5 +6,5 @@ struct A {
 };
 
 struct B: public A {
-  void f(int); // { dg-warning "" } by this
+  void f(int); // { dg-message "" } by this
 };