aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-06-24 14:40:12 -0400
committerJason Merrill <jason@redhat.com>2022-06-24 18:23:48 -0400
commit113844d68e94f4e9c0e946db351ba7d3d4a1335a (patch)
tree4700337540406594bea63da9bf9543c45207dd64 /gcc/doc
parent75fa80bb5654d1f8b21310118f41705b74168039 (diff)
downloadgcc-113844d68e94f4e9c0e946db351ba7d3d4a1335a.zip
gcc-113844d68e94f4e9c0e946db351ba7d3d4a1335a.tar.gz
gcc-113844d68e94f4e9c0e946db351ba7d3d4a1335a.tar.bz2
c++: Include -Woverloaded-virtual in -Wall [PR87729]
This seems like a good warning to have in -Wall, as requested. But as pointed out in PR20423, some users want a warning only when a derived function doesn't override any base function. So let's put that lesser version in -Wall (and -Woverloaded-virtual=1) while leaving the semantics for the existing option the same. PR c++/87729 PR c++/20423 gcc/c-family/ChangeLog: * c.opt (Woverloaded-virtual): Add levels, include in -Wall. gcc/ChangeLog: * doc/invoke.texi: Document changes. gcc/cp/ChangeLog: * class.cc (warn_hidden): Handle -Woverloaded-virtual=1. gcc/testsuite/ChangeLog: * g++.dg/warn/Woverloaded-virt1.C: New test. * g++.dg/warn/Woverloaded-virt2.C: New test.
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/invoke.texi26
1 files changed, 25 insertions, 1 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index f794edd..dfaa561 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4039,6 +4039,7 @@ a C++ program. The new-style casts (@code{dynamic_cast},
less vulnerable to unintended effects and much easier to search for.
@item -Woverloaded-virtual @r{(C++ and Objective-C++ only)}
+@itemx -Woverloaded-virtual=@var{n}
@opindex Woverloaded-virtual
@opindex Wno-overloaded-virtual
@cindex overloaded virtual function, warning
@@ -4052,7 +4053,7 @@ struct A @{
@};
struct B: public A @{
- void f(int);
+ void f(int); // does not override
@};
@end smallexample
@@ -4067,6 +4068,29 @@ b->f();
@noindent
fails to compile.
+The optional level suffix controls the behavior when all the
+declarations in the derived class override virtual functions in the
+base class, even if not all of the base functions are overridden:
+
+@smallexample
+struct C @{
+ virtual void f();
+ virtual void f(int);
+@};
+
+struct D: public C @{
+ void f(int); // does override
+@}
+@end smallexample
+
+This pattern is less likely to be a mistake; if D is only used
+virtually, the user might have decided that the base class semantics
+for some of the overloads are fine.
+
+At level 1, this case does not warn; at level 2, it does.
+@option{-Woverloaded-virtual} by itself selects level 2. Level 1 is
+included in @option{-Wall}.
+
@item -Wno-pmf-conversions @r{(C++ and Objective-C++ only)}
@opindex Wno-pmf-conversions
@opindex Wpmf-conversions