From: tbsaunde+gcc@tbsaunde.org
To: jason@redhat.com
Cc: gcc-patches@gcc.gnu.org, Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
Subject: [PATCH] pr31397 - implement -Wsuggest-override
Date: Wed, 24 Dec 2014 08:36:00 -0000 [thread overview]
Message-ID: <1419390864-16128-1-git-send-email-tbsaunde+gcc@tbsaunde.org> (raw)
In-Reply-To: <5491F3DB.2000102@redhat.com>
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
Hi,
comments fixed. bootstrapped on x86_64-linux, new test passes and regtest
pending, ok?
Trev
c-family/
* c.opt (Wsuggest-override): New option.
cp/
* class.c (check_for_override): Warn when a virtual function is an
override not marked override.
gcc/
* doc/invoke.texi: Document -Wsuggest-override.
---
gcc/c-family/c.opt | 5 +++++
gcc/cp/class.c | 4 ++++
gcc/doc/invoke.texi | 6 +++++-
gcc/testsuite/g++.dg/warn/Wsuggest-override.C | 23 +++++++++++++++++++++++
4 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/warn/Wsuggest-override.C
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index f86718b..1f6f793 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -578,6 +578,11 @@ Wsuggest-attribute=format
C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
Warn about functions which might be candidates for format attributes
+Wsuggest-override
+C++ ObjC++ Var(warn_override) Warning
+Suggest that the override keyword be used when the declaration of a virtual
+function overrides another.
+
Wswitch
C ObjC C++ ObjC++ Var(warn_switch) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn about enumerated switches, with no default, missing a case
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 0ac2124..d2cf4a0 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2811,6 +2811,10 @@ check_for_override (tree decl, tree ctype)
{
DECL_VINDEX (decl) = decl;
overrides_found = true;
+ if (warn_override && !DECL_OVERRIDE_P (decl)
+ && !DECL_DESTRUCTOR_P (decl))
+ warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
+ "%q+D can be marked override", decl);
}
if (DECL_VIRTUAL_P (decl))
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9f56f42..d0ee093 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -277,7 +277,7 @@ Objective-C and Objective-C++ Dialects}.
-Wstack-protector -Wstack-usage=@var{len} -Wstrict-aliasing @gol
-Wstrict-aliasing=n @gol -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
-Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol
--Wsuggest-final-types @gol -Wsuggest-final-methods @gol
+-Wsuggest-final-types @gol -Wsuggest-final-methods @gol -Wsuggest-override @gol
-Wmissing-format-attribute @gol
-Wswitch -Wswitch-default -Wswitch-enum -Wswitch-bool -Wsync-nand @gol
-Wsystem-headers -Wtrampolines -Wtrigraphs -Wtype-limits -Wundef @gol
@@ -4276,6 +4276,10 @@ class hierarchy graph is more complete. It is recommended to first consider
suggestions of @option{-Wsuggest-final-types} and then rebuild with new
annotations.
+@item -Wsuggest-override
+Warn about overriding virtual functions that are not marked with the override
+keyword.
+
@item -Warray-bounds
@opindex Wno-array-bounds
@opindex Warray-bounds
diff --git a/gcc/testsuite/g++.dg/warn/Wsuggest-override.C b/gcc/testsuite/g++.dg/warn/Wsuggest-override.C
new file mode 100644
index 0000000..f820f4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wsuggest-override.C
@@ -0,0 +1,23 @@
+// { dg-do compile }
+// { dg-options "-std=c++11 -Wsuggest-override" }
+struct A
+{
+ A();
+ virtual ~A();
+ virtual void f();
+ virtual int bar();
+ int c();
+ operator int();
+ virtual operator float();
+};
+
+struct B : A
+{
+ B();
+ virtual ~B();
+ virtual void f(); // { dg-warning "can be marked override" }
+virtual int bar() override;
+int c();
+operator int();
+virtual operator float(); // { dg-warning "can be marked override" }
+};
--
2.1.3
next prev parent reply other threads:[~2014-12-24 3:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 8:53 [PATCH 1/2] [C++] Remove tree_list from warn_hidden tsaunders
2014-11-27 8:55 ` [PATCH 2/2] [C++] pr31397 - implement -Wsuggest-override tsaunders
2014-12-17 21:22 ` Jason Merrill
2014-12-18 17:00 ` Trevor Saunders
2014-12-24 8:36 ` tbsaunde+gcc [this message]
2014-12-25 15:15 ` [PATCH] " Jason Merrill
2014-12-17 21:21 ` [PATCH 1/2] [C++] Remove tree_list from warn_hidden Jason Merrill
-- strict thread matches above, loose matches on Subject: below --
2014-11-25 16:55 [PATCH] pr31397 - implement -Wsuggest-override tsaunders
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1419390864-16128-1-git-send-email-tbsaunde+gcc@tbsaunde.org \
--to=tbsaunde+gcc@tbsaunde.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).