diff options
author | tbsaunde <tbsaunde@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-01-06 02:02:47 +0000 |
---|---|---|
committer | tbsaunde <tbsaunde@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-01-06 02:02:47 +0000 |
commit | 678a4e3edeae059cdc1587156d2d1b42b9568f9f (patch) | |
tree | e105777f028705614c3513197fcc19cd6e120408 | |
parent | 4a0bdf06eef8c001c4c6c1852011c418eb0975b1 (diff) | |
download | gcc-678a4e3edeae059cdc1587156d2d1b42b9568f9f.tar.gz |
implement -Wsuggest-override
c-family/
PR c++/31397
* c.opt (Wsuggest-override): New option.
cp/
PR c++/31397
* class.c (check_for_override): Warn when a virtual function is an
override not marked override.
gcc/
PR c++/31397
* doc/invoke.texi: Document -Wsuggest-override.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219213 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 5 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/class.c | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wsuggest-override.C | 23 |
7 files changed, 53 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a50e56a089a..87d60b3dc22 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-01-05 Trevor Saunders <tsaunders@mozilla.com> + + PR c++/31397 + * doc/invoke.texi: Document -Wsuggest-override. + 2015-01-05 Radovan Obradovic <radovan.obradovic@imgtec.com> PR rtl-optimization/64287 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 47eb1597c6f..4c86fa511d3 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-01-05 Trevor Saunders <tsaunders@mozilla.com> + + PR c++/31397 + * c.opt (Wsuggest-override): New option. + 2015-01-05 Jakub Jelinek <jakub@redhat.com> Update copyright years. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 6c23fa89a55..064c69e5a1d 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/ChangeLog b/gcc/cp/ChangeLog index 1163df3d427..004629b8848 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2015-01-05 Trevor Saunders <tsaunders@mozilla.com> + PR c++/31397 + * class.c (check_for_override): Warn when a virtual function is an + override not marked override. + +2015-01-05 Trevor Saunders <tsaunders@mozilla.com> + * class.c (warn_hidden): Use auto_vec<tree> instead of tree_list to hold base_fndecls. (get_basefndecls): Adjust. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 3b4aff89f7b..b798a52702f 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 21784aa2d8f..c7a61b8fd53 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 @@ -4282,6 +4282,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 00000000000..f820f4b82c1 --- /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" } +}; |