brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f632c81 Raw
46 lines · plain
1.. title:: clang-tidy - modernize-use-equals-delete2 3modernize-use-equals-delete4===========================5 6Identifies unimplemented private special member functions, and recommends using7``= delete`` for them. Additionally, it recommends relocating any deleted8member function from the ``private`` to the ``public`` section.9 10Before the introduction of C++11, the primary method to effectively "erase" a11particular function involved declaring it as ``private`` without providing a12definition. This approach would result in either a compiler error (when13attempting to call a private function) or a linker error (due to an undefined14reference).15 16However, subsequent to the advent of C++11, a more conventional approach17emerged for achieving this purpose. It involves flagging functions as18``= delete`` and keeping them in the ``public`` section of the class.19 20To prevent false positives, this check is only active within a translation21unit where all other member functions have been implemented. The check will22generate partial fixes by introducing ``= delete``, but the user is responsible23for manually relocating functions to the ``public`` section.24 25.. code-block:: c++26 27  // Example: bad28  class A {29   private:30    A(const A&);31    A& operator=(const A&);32  };33 34  // Example: good35  class A {36   public:37    A(const A&) = delete;38    A& operator=(const A&) = delete;39  };40 41 42.. option:: IgnoreMacros43 44   If this option is set to `true` (default is `true`), the check will not warn45   about functions declared inside macros.46