File: use-equals-delete.rst

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (45 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (9)
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
.. title:: clang-tidy - modernize-use-equals-delete

modernize-use-equals-delete
===========================

Identifies unimplemented private special member functions, and recommends using
``= delete`` for them. Additionally, it recommends relocating any deleted
member function from the ``private`` to the ``public`` section.

Before the introduction of C++11, the primary method to effectively "erase" a
particular function involved declaring it as ``private`` without providing a
definition. This approach would result in either a compiler error (when
attempting to call a private function) or a linker error (due to an undefined
reference).

However, subsequent to the advent of C++11, a more conventional approach emerged
for achieving this purpose. It involves flagging functions as ``= delete`` and
keeping them in the ``public`` section of the class.

To prevent false positives, this check is only active within a translation
unit where all other member functions have been implemented. The check will
generate partial fixes by introducing ``= delete``, but the user is responsible
for manually relocating functions to the ``public`` section.

.. code-block:: c++

  // Example: bad
  class A {
   private:
    A(const A&);
    A& operator=(const A&);
  };

  // Example: good
  class A {
   public:
    A(const A&) = delete;
    A& operator=(const A&) = delete;
  };


.. option:: IgnoreMacros

   If this option is set to `true` (default is `true`), the check will not warn
   about functions declared inside macros.