public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/78010 - bogus -Wsuggest-override warning on final function
@ 2019-05-06 21:07 Marek Polacek
  2019-05-10 14:45 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2019-05-06 21:07 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

-Wsuggest-override warns for virtual functions that could use the override
keyword.  But as everyone in this PR agrees, the warning shouldn't suggest
adding "override" for "final" functions.  This trivial patch implements that.

Bootstrapped/regtested on x86_64-linux, ok for trunk/9?

2019-05-06  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.

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

diff --git gcc/cp/class.c gcc/cp/class.c
index 712169ce7e7..a47777cdd9e 100644
--- gcc/cp/class.c
+++ gcc/cp/class.c
@@ -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);
diff --git gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C
new file mode 100644
index 00000000000..4948902e930
--- /dev/null
+++ gcc/testsuite/g++.dg/warn/Wsuggest-override-2.C
@@ -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" }
+};

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C++ PATCH for c++/78010 - bogus -Wsuggest-override warning on final function
  2019-05-06 21:07 C++ PATCH for c++/78010 - bogus -Wsuggest-override warning on final function Marek Polacek
@ 2019-05-10 14:45 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-05-10 14:45 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 5/6/19 5:07 PM, Marek Polacek wrote:
> -Wsuggest-override warns for virtual functions that could use the override
> keyword.  But as everyone in this PR agrees, the warning shouldn't suggest
> adding "override" for "final" functions.  This trivial patch implements that.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk/9?

OK.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-10 14:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 21:07 C++ PATCH for c++/78010 - bogus -Wsuggest-override warning on final function Marek Polacek
2019-05-10 14:45 ` Jason Merrill

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).