Warn if a string is longer than the maximum portable length specified by the standard.
Woverloaded-virtual
-C++ ObjC++ Var(warn_overloaded_virtual) Warning
+C++ ObjC++ Warning Alias(Woverloaded-virtual=,2,0)
+Warn about overloaded virtual function names.
+
+Woverloaded-virtual=
+C++ ObjC++ Joined UInteger IntegerRange(0,2) Var(warn_overloaded_virtual) Warning LangEnabledBy(C++ ObjC++,Wall,1,0)
Warn about overloaded virtual function names.
Woverride-init
continue;
/* Remove any overridden functions. */
+ bool seen_non_override = false;
for (tree fndecl : ovl_range (fns))
{
if (TREE_CODE (fndecl) == FUNCTION_DECL
for (size_t k = 0; k < base_fndecls.length (); k++)
if (base_fndecls[k]
&& same_signature_p (fndecl, base_fndecls[k]))
- base_fndecls[k] = NULL_TREE;
+ {
+ base_fndecls[k] = NULL_TREE;
+ goto next;
+ }
}
+ seen_non_override = true;
+ next:;
}
+ if (!seen_non_override && warn_overloaded_virtual == 1)
+ /* All the derived fns override base virtuals. */
+ return;
+
/* Now give a warning for all base functions without overriders,
as they are hidden. */
- tree base_fndecl;
- FOR_EACH_VEC_ELT (base_fndecls, j, base_fndecl)
+ for (tree base_fndecl : base_fndecls)
if (base_fndecl)
{
auto_diagnostic_group d;
/* Here we know it is a hider, and no overrider exists. */
if (warning_at (location_of (base_fndecl),
- OPT_Woverloaded_virtual,
+ OPT_Woverloaded_virtual_,
"%qD was hidden", base_fndecl))
inform (location_of (fns), " by %qD", fns);
}
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
@};
struct B: public A @{
- void f(int);
+ void f(int); // does not override
@};
@end smallexample
@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
--- /dev/null
+// PR c++/87729
+// { dg-additional-options -Wall }
+
+class Foo
+{
+public:
+ virtual void f(int); // { dg-warning "hidden" }
+};
+
+class Bar : public Foo
+{
+public:
+ virtual void f(short); // { dg-message "by" }
+};
--- /dev/null
+// PR c++/20423
+// { dg-additional-options -Wall }
+
+class Foo
+{
+public:
+ virtual void f(int);
+ virtual void f(short);
+};
+
+class Bar : public Foo
+{
+public:
+ virtual void f(short);
+};