| 1 |
.. title:: clang-tidy - modernize-use-equals-delete |
| 2 |
|
| 3 |
modernize-use-equals-delete |
| 4 |
=========================== |
| 5 |
|
| 6 |
Identifies unimplemented private special member functions, and recommends using |
| 7 |
``= delete`` for them. Additionally, it recommends relocating any deleted |
| 8 |
member function from the ``private`` to the ``public`` section. |
| 9 |
|
| 10 |
Before the introduction of C++11, the primary method to effectively "erase" a |
| 11 |
particular function involved declaring it as ``private`` without providing a |
| 12 |
definition. This approach would result in either a compiler error (when |
| 13 |
attempting to call a private function) or a linker error (due to an undefined |
| 14 |
reference). |
| 15 |
|
| 16 |
However, subsequent to the advent of C++11, a more conventional approach emerged |
| 17 |
for achieving this purpose. It involves flagging functions as ``= delete`` and |
| 18 |
keeping them in the ``public`` section of the class. |
| 19 |
|
| 20 |
To prevent false positives, this check is only active within a translation |
| 21 |
unit where all other member functions have been implemented. The check will |
| 22 |
generate partial fixes by introducing ``= delete``, but the user is responsible |
| 23 |
for manually relocating functions to the ``public`` section. |
| 24 |
|
| 25 |
.. code-block:: c++ |
| 26 |
|
| 27 |
// Example: bad |
| 28 |
class A { |
| 29 |
private: |
| 30 |
A(const A&); |
| 31 |
A& operator=(const A&); |
| 32 |
}; |
| 33 |
|
| 34 |
// Example: good |
| 35 |
class A { |
| 36 |
public: |
| 37 |
A(const A&) = delete; |
| 38 |
A& operator=(const A&) = delete; |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
.. option:: IgnoreMacros |
| 43 |
|
| 44 |
If this option is set to `true` (default is `true`), the check will not warn |
| 45 |
about functions declared inside macros. |