1.. title:: clang-tidy - modernize-replace-disallow-copy-and-assign-macro 2 3modernize-replace-disallow-copy-and-assign-macro 4================================================ 5 6Finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and replaces them 7with a deleted copy constructor and a deleted assignment operator. 8 9Before the ``delete`` keyword was introduced in C++11 it was common practice to 10declare a copy constructor and an assignment operator as a private members. This 11effectively makes them unusable to the public API of a class. 12 13With the advent of the ``delete`` keyword in C++11 we can abandon the 14``private`` access of the copy constructor and the assignment operator and 15delete the methods entirely. 16 17When running this check on a code like this: 18 19.. code-block:: c++ 20 21 class Foo { 22 private: 23 DISALLOW_COPY_AND_ASSIGN(Foo); 24 }; 25 26It will be transformed to this: 27 28.. code-block:: c++ 29 30 class Foo { 31 private: 32 Foo(const Foo &) = delete; 33 const Foo &operator=(const Foo &) = delete; 34 }; 35 36Known Limitations 37----------------- 38 39* Notice that the migration example above leaves the ``private`` access 40 specification untouched. You might want to run the check :doc:`modernize-use-equals-delete 41 <modernize-use-equals-delete>` to get warnings for deleted functions in 42 private sections. 43 44Options 45------- 46 47.. option:: MacroName 48 49 A string specifying the macro name whose expansion will be replaced. 50 Default is `DISALLOW_COPY_AND_ASSIGN`. 51 52See: https://en.cppreference.com/w/cpp/language/function#Deleted_functions 53