| 1 |
.. title:: clang-tidy - modernize-use-override |
| 2 |
|
| 3 |
modernize-use-override |
| 4 |
====================== |
| 5 |
|
| 6 |
Adds ``override`` (introduced in C++11) to overridden virtual functions and |
| 7 |
removes ``virtual`` from those functions as it is not required. |
| 8 |
|
| 9 |
``virtual`` on non base class implementations was used to help indicate to the |
| 10 |
user that a function was virtual. C++ compilers did not use the presence of |
| 11 |
this to signify an overridden function. |
| 12 |
|
| 13 |
In C++11 ``override`` and ``final`` keywords were introduced to allow |
| 14 |
overridden functions to be marked appropriately. Their presence allows |
| 15 |
compilers to verify that an overridden function correctly overrides a base |
| 16 |
class implementation. |
| 17 |
|
| 18 |
This can be useful as compilers can generate a compile time error when: |
| 19 |
|
| 20 |
- The base class implementation function signature changes. |
| 21 |
- The user has not created the override with the correct signature. |
| 22 |
|
| 23 |
Options |
| 24 |
------- |
| 25 |
|
| 26 |
.. option:: IgnoreDestructors |
| 27 |
|
| 28 |
If set to `true`, this check will not diagnose destructors. Default is `false`. |
| 29 |
|
| 30 |
.. option:: IgnoreTemplateInstantiations |
| 31 |
|
| 32 |
If set to `true`, instructs this check to ignore virtual function overrides |
| 33 |
that are part of template instantiations. Default is `false`. |
| 34 |
|
| 35 |
.. option:: AllowOverrideAndFinal |
| 36 |
|
| 37 |
If set to `true`, this check will not diagnose ``override`` as redundant |
| 38 |
with ``final``. This is useful when code will be compiled by a compiler with |
| 39 |
warning/error checking flags requiring ``override`` explicitly on overridden |
| 40 |
members, such as ``gcc -Wsuggest-override``/``gcc -Werror=suggest-override``. |
| 41 |
Default is `false`. |
| 42 |
|
| 43 |
.. option:: OverrideSpelling |
| 44 |
|
| 45 |
Specifies a macro to use instead of ``override``. This is useful when |
| 46 |
maintaining source code that also needs to compile with a pre-C++11 |
| 47 |
compiler. |
| 48 |
|
| 49 |
.. option:: FinalSpelling |
| 50 |
|
| 51 |
Specifies a macro to use instead of ``final``. This is useful when |
| 52 |
maintaining source code that also needs to compile with a pre-C++11 |
| 53 |
compiler. |
| 54 |
|
| 55 |
.. note:: |
| 56 |
|
| 57 |
For more information on the use of ``override`` see https://en.cppreference.com/w/cpp/language/override |