brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 4906b50 Raw
32 lines · plain
1.. title:: clang-tidy - bugprone-derived-method-shadowing-base-method2 3bugprone-derived-method-shadowing-base-method4=============================================5 6Finds derived class methods that shadow a (non-virtual) base class method.7 8In order to be considered "shadowing", methods must have the same signature9(i.e. the same name, same number of parameters, same parameter types, etc).10Only checks public, non-templated methods.11 12The below example is bugprone because consumers of the ``Derived`` class will13expect the ``reset`` method to do the work of ``Base::reset()`` in addition to14extra work required to reset the ``Derived`` class.  Common fixes include:15 16- Making the ``reset`` method polymorphic17- Re-naming ``Derived::reset`` if it's not meant to intersect with18  ``Base::reset``19- Using ``using Base::reset`` to change the access specifier20 21This is also a violation of the Liskov Substitution Principle.22 23.. code-block:: c++24 25  struct Base {26    void reset() {/* reset the base class */};27  };28 29  struct Derived : public Base {30    void reset() {/* reset the derived class, but not the base class */};31  };32