File: special-member-functions.rst

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (73 lines) | stat: -rw-r--r-- 2,297 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.. title:: clang-tidy - cppcoreguidelines-special-member-functions

cppcoreguidelines-special-member-functions
==========================================

The check finds classes where some but not all of the special member functions
are defined.

By default the compiler defines a copy constructor, copy assignment operator,
move constructor, move assignment operator and destructor. The default can be
suppressed by explicit user-definitions. The relationship between which
functions will be suppressed by definitions of other functions is complicated
and it is advised that all five are defaulted or explicitly defined.

Note that defining a function with ``= delete`` is considered to be a
definition.

This check implements `C.21
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five>`_
from the C++ Core Guidelines.

Options
-------

.. option:: AllowSoleDefaultDtor

   When set to `true` (default is `false`), this check will only trigger on
   destructors if they are defined and not defaulted.

   .. code-block:: c++

     struct A { // This is fine.
       virtual ~A() = default;
     };

     struct B { // This is not fine.
       ~B() {}
     };

     struct C {
       // This is not checked, because the destructor might be defaulted in
       // another translation unit.
       ~C();
     };

.. option:: AllowMissingMoveFunctions

   When set to `true` (default is `false`), this check doesn't flag classes which define no move
   operations at all. It still flags classes which define only one of either
   move constructor or move assignment operator. With this option enabled, the following class won't be flagged:

   .. code-block:: c++

     struct A {
       A(const A&);
       A& operator=(const A&);
       ~A();
     };

.. option:: AllowMissingMoveFunctionsWhenCopyIsDeleted

   When set to `true` (default is `false`), this check doesn't flag classes which define deleted copy
   operations but don't define move operations. This flag is related to Google C++ Style Guide
   https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types. With this option enabled, the
   following class won't be flagged:

   .. code-block:: c++

     struct A {
       A(const A&) = delete;
       A& operator=(const A&) = delete;
       ~A();
     };