Skip to content

Commit 19465b6

Browse files
author
Tom James
committed
Give an example in the documentation
1 parent d22bfa4 commit 19465b6

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/method-hiding.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,24 @@ Finds derived class methods that hide a (non-virtual) base class method.
77

88
In order to be considered "hiding", methods must have the same signature
99
(i.e. the same name, same number of parameters, same parameter types, etc).
10-
Only checks public, non-templated methods.
10+
Only checks public, non-templated methods.
11+
12+
The below example is bugprone because consumers of the `Derived` class will
13+
expect the `reset` method to do the work of `Base::reset()` in addition to extra
14+
work required to reset the `Derived` class. Common fixes include:
15+
- Making the `reset` method polymorphic
16+
- Re-naming `Derived::reset` if it's not meant to intersect with `Base::reset`
17+
- Using `using Base::reset` to change the access specifier
18+
19+
This is also a violation of the Liskov Substitution Principle.
20+
21+
.. code-block:: c++
22+
23+
class Base {
24+
void reset() {/* reset the base class */};
25+
};
26+
27+
class Derived : public Base {
28+
public:
29+
void reset() {/* reset the derived class, but not the base class */};
30+
};

0 commit comments

Comments
 (0)