PR c++/78010 - bogus -Wsuggest-override warning on final function.
authorMarek Polacek <polacek@redhat.com>
Fri, 10 May 2019 14:53:30 +0000 (14:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 10 May 2019 14:53:30 +0000 (14:53 +0000)
* class.c (check_for_override): Don't warn for final functions.

* g++.dg/warn/Wsuggest-override-2.C: New test.

From-SVN: r271065

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C [new file with mode: 0644]

index a1c32a1105962244a6f0fd90a541c394579a76c9..a43001a1a111ad2ba143e94db23d0b6cfa25a3f3 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-10  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/78010 - bogus -Wsuggest-override warning on final function.
+       * class.c (check_for_override): Don't warn for final functions.
+
 2019-05-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR pch/90326
index 712169ce7e766ebf5e7a3e35a18704e50b9a2d0b..a47777cdd9ef4d03d1652fa6e8c72b9b595b323f 100644 (file)
@@ -2780,7 +2780,9 @@ check_for_override (tree decl, tree ctype)
     {
       DECL_VINDEX (decl) = decl;
       overrides_found = true;
-      if (warn_override && !DECL_OVERRIDE_P (decl)
+      if (warn_override
+         && !DECL_OVERRIDE_P (decl)
+         && !DECL_FINAL_P (decl)
          && !DECL_DESTRUCTOR_P (decl))
        warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
                    "%qD can be marked override", decl);
index b42e68cf849f2dcd48ba75bb58c0225e6e8835f8..ac85d094f428e93030a3605699c045c735d1be61 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-10  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/78010 - bogus -Wsuggest-override warning on final function.
+       * g++.dg/warn/Wsuggest-override-2.C: New test.
+
 2019-05-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/90385
diff --git a/gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C b/gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C
new file mode 100644 (file)
index 0000000..4948902
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/78010
+// { dg-options "-std=c++11 -Wsuggest-override" }
+
+struct A {
+  virtual void f();
+};
+struct B : A {
+  void f() final; // { dg-bogus "can be marked override" }
+};