File: modernize-replace-disallow-copy-and-assign-macro.rst

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (52 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download | duplicates (2)
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
.. title:: clang-tidy - modernize-replace-disallow-copy-and-assign-macro

modernize-replace-disallow-copy-and-assign-macro
================================================

Finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and replaces them
with a deleted copy constructor and a deleted assignment operator.

Before the ``delete`` keyword was introduced in C++11 it was common practice to
declare a copy constructor and an assignment operator as a private members. This
effectively makes them unusable to the public API of a class.

With the advent of the ``delete`` keyword in C++11 we can abandon the
``private`` access of the copy constructor and the assignment operator and
delete the methods entirely.

When running this check on a code like this:

.. code-block:: c++

  class Foo {
  private:
    DISALLOW_COPY_AND_ASSIGN(Foo);
  };

It will be transformed to this:

.. code-block:: c++

  class Foo {
  private:
    Foo(const Foo &) = delete;
    const Foo &operator=(const Foo &) = delete;
  };

Known Limitations
-----------------

* Notice that the migration example above leaves the ``private`` access
  specification untouched. You might want to run the check:doc:`modernize-use-equals-delete
  <modernize-use-equals-delete>` to get warnings for deleted functions in
  private sections.

Options
-------

.. option:: MacroName

   A string specifying the macro name whose expansion will be replaced.
   Default is `DISALLOW_COPY_AND_ASSIGN`.

See: https://en.cppreference.com/w/cpp/language/function#Deleted_functions