brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 485abca Raw
54 lines · plain
1.. title:: clang-tidy - modernize-replace-disallow-copy-and-assign-macro2 3modernize-replace-disallow-copy-and-assign-macro4================================================5 6Finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and replaces them7with a deleted copy constructor and a deleted assignment operator.8 9Before the ``delete`` keyword was introduced in C++11 it was common practice to10declare a copy constructor and an assignment operator as private members. This11effectively makes them unusable to the public API of a class.12 13With the advent of the ``delete`` keyword in C++11 we can abandon the14``private`` access of the copy constructor and the assignment operator and15delete 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 36 37Limitations38-----------39 40* Notice that the migration example above leaves the ``private`` access41  specification untouched. You might want to run the check42  :doc:`modernize-use-equals-delete <../modernize/use-equals-delete>`43  to get warnings for deleted functions in private sections.44 45Options46-------47 48.. option:: MacroName49 50   A string specifying the macro name whose expansion will be replaced.51   Default is `DISALLOW_COPY_AND_ASSIGN`.52 53See: https://en.cppreference.com/w/cpp/language/function#Deleted_functions54