Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst

raw
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:: AllowOverrideAndFinal
31
32 If set to `true`, this check will not diagnose ``override`` as redundant
33 with ``final``. This is useful when code will be compiled by a compiler with
34 warning/error checking flags requiring ``override`` explicitly on overridden
35 members, such as ``gcc -Wsuggest-override``/``gcc -Werror=suggest-override``.
36 Default is `false`.
37
38 .. option:: OverrideSpelling
39
40 Specifies a macro to use instead of ``override``. This is useful when
41 maintaining source code that also needs to compile with a pre-C++11
42 compiler.
43
44 .. option:: FinalSpelling
45
46 Specifies a macro to use instead of ``final``. This is useful when
47 maintaining source code that also needs to compile with a pre-C++11
48 compiler.
49
50 .. note::
51
52 For more information on the use of ``override`` see https://en.cppreference.com/w/cpp/language/override