93 lines · plain
1.. title:: clang-tidy - cppcoreguidelines-special-member-functions2 3cppcoreguidelines-special-member-functions4==========================================5 6The check finds classes where some but not all of the special member functions7are defined.8 9By default the compiler defines a copy constructor, copy assignment operator,10move constructor, move assignment operator and destructor. The default can be11suppressed by explicit user-definitions. The relationship between which12functions will be suppressed by definitions of other functions is complicated13and it is advised that all five are defaulted or explicitly defined.14 15Note that defining a function with ``= delete`` is considered to be a16definition.17 18This check implements `C.2119<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-five>`_20from the C++ Core Guidelines.21 22Options23-------24 25.. option:: AllowSoleDefaultDtor26 27 When set to `true` (default is `false`), this check will only trigger on28 destructors if they are defined and not defaulted.29 30 .. code-block:: c++31 32 struct A { // This is fine.33 virtual ~A() = default;34 };35 36 struct B { // This is not fine.37 ~B() {}38 };39 40 struct C {41 // This is not checked, because the destructor might be defaulted in42 // another translation unit.43 ~C();44 };45 46.. option:: AllowMissingMoveFunctions47 48 When set to `true` (default is `false`), this check doesn't flag classes49 which define no move operations at all. It still flags classes which define50 only one of either move constructor or move assignment operator. With this51 option enabled, the following class won't be flagged:52 53 .. code-block:: c++54 55 struct A {56 A(const A&);57 A& operator=(const A&);58 ~A();59 };60 61.. option:: AllowMissingMoveFunctionsWhenCopyIsDeleted62 63 When set to `true` (default is `false`), this check doesn't flag classes64 which define deleted copy operations but don't define move operations. This65 flag is related to Google C++ Style Guide `Copyable and Movable Types66 <https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types>`_.67 With this option enabled, the following class won't be flagged:68 69 .. code-block:: c++70 71 struct A {72 A(const A&) = delete;73 A& operator=(const A&) = delete;74 ~A();75 };76 77.. option:: AllowImplicitlyDeletedCopyOrMove78 79 When set to `true` (default is `false`), this check doesn't flag classes80 which implicitly delete copy or move operations.81 With this option enabled, the following class won't be flagged:82 83 .. code-block:: c++84 85 struct A : boost::noncopyable {86 ~A() { std::cout << "dtor\n"; }87 };88 89.. option:: IgnoreMacros90 91 If set to `true`, the check will not give warnings for classes defined92 inside macros. Default is `true`.93