1.. title:: clang-tidy - cppcoreguidelines-special-member-functions 2 3cppcoreguidelines-special-member-functions 4========================================== 5 6The check finds classes where some but not all of the special member functions 7are defined. 8 9By default the compiler defines a copy constructor, copy assignment operator, 10move constructor, move assignment operator and destructor. The default can be 11suppressed by explicit user-definitions. The relationship between which 12functions will be suppressed by definitions of other functions is complicated 13and it is advised that all five are defaulted or explicitly defined. 14 15Note that defining a function with ``= delete`` is considered to be a 16definition. 17 18This check implements `C.21 19<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five>`_ 20from the C++ Core Guidelines. 21 22Options 23------- 24 25.. option:: AllowSoleDefaultDtor 26 27 When set to `true` (default is `false`), this check will only trigger on 28 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 in 42 // another translation unit. 43 ~C(); 44 }; 45 46.. option:: AllowMissingMoveFunctions 47 48 When set to `true` (default is `false`), this check doesn't flag classes 49 which define no move operations at all. It still flags classes which define 50 only one of either move constructor or move assignment operator. With this 51 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:: AllowMissingMoveFunctionsWhenCopyIsDeleted 62 63 When set to `true` (default is `false`), this check doesn't flag classes 64 which define deleted copy operations but don't define move operations. This 65 flag is related to Google C++ Style Guide `Copyable and Movable Types 66 <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:: AllowImplicitlyDeletedCopyOrMove 78 79 When set to `true` (default is `false`), this check doesn't flag classes 80 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