Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst

raw
1 .. title:: clang-tidy - cppcoreguidelines-special-member-functions
2
3 cppcoreguidelines-special-member-functions
4 ==========================================
5
6 The check finds classes where some but not all of the special member functions
7 are defined.
8
9 By default the compiler defines a copy constructor, copy assignment operator,
10 move constructor, move assignment operator and destructor. The default can be
11 suppressed by explicit user-definitions. The relationship between which
12 functions will be suppressed by definitions of other functions is complicated
13 and it is advised that all five are defaulted or explicitly defined.
14
15 Note that defining a function with ``= delete`` is considered to be a
16 definition.
17
18 This rule is part of the "Constructors, assignments, and destructors" profile of the C++ Core
19 Guidelines, corresponding to rule C.21. See
20
21 https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all.
22
23 Options
24 -------
25
26 .. option:: AllowSoleDefaultDtor
27
28 When set to `true` (default is `false`), this check doesn't flag classes with a sole, explicitly
29 defaulted destructor. An example for such a class is:
30
31 .. code-block:: c++
32
33 struct A {
34 virtual ~A() = default;
35 };
36
37 .. option:: AllowMissingMoveFunctions
38
39 When set to `true` (default is `false`), this check doesn't flag classes which define no move
40 operations at all. It still flags classes which define only one of either
41 move constructor or move assignment operator. With this option enabled, the following class won't be flagged:
42
43 .. code-block:: c++
44
45 struct A {
46 A(const A&);
47 A& operator=(const A&);
48 ~A();
49 };
50
51 .. option:: AllowMissingMoveFunctionsWhenCopyIsDeleted
52
53 When set to `true` (default is `false`), this check doesn't flag classes which define deleted copy
54 operations but don't define move operations. This flag is related to Google C++ Style Guide
55 https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types. With this option enabled, the
56 following class won't be flagged:
57
58 .. code-block:: c++
59
60 struct A {
61 A(const A&) = delete;
62 A& operator=(const A&) = delete;
63 ~A();
64 };