Carlos =?utf-8?q?Gálvez?= <carlos.gal...@zenseact.com>, Carlos =?utf-8?q?Gálvez?= <carlos.gal...@zenseact.com>, Carlos =?utf-8?q?Gálvez?= <carlos.gal...@zenseact.com>, Carlos =?utf-8?q?Gálvez?= <carlos.gal...@zenseact.com>, Carlos =?utf-8?q?Gálvez?= <carlos.gal...@zenseact.com>
https://github.com/carlosgalvezp updated https://github.com/llvm/llvm-project/pull/65231: >From 9c5fec5e31f31b59262646625b7d34f23d57d6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 18:24:55 +0000 Subject: [PATCH 1/6] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals-delete So the purpose of the check is more clear. Update examples code to show compliant code. Fixes #65221 --- .../checks/modernize/use-equals-delete.rst | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst index c3de904e253802..47de4185667a3e 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst @@ -3,22 +3,34 @@ modernize-use-equals-delete =========================== +Prior to C++11, the only way to "delete" a given function was to make it +``private`` and without definition, to generate a compiler error (calling +private function) or a linker error (undefined reference). + +After C++11, the more idiomatic way to achieve this is by marking the functions +as ``= delete``, and keeping them in the ``public`` section. + This check marks unimplemented private special member functions with ``= delete``. +Additionally, it warns about ``delete``'d functions still kept in the ``private`` +section, that should be moved to the ``public`` one instead. + To avoid false-positives, this check only applies in a translation unit that has -all other member functions implemented. +all other member functions implemented. The check will generate partial fixes +by adding ``= delete``, but the user must manually move it to the ``public`` +section. .. code-block:: c++ - struct A { - private: + // Example: bad + class A { + private: A(const A&); A& operator=(const A&); }; - // becomes - - struct A { - private: + // Example: good + class A { + public: A(const A&) = delete; A& operator=(const A&) = delete; }; >From aba8f0d712fd78db75a0387dde968e18d87b5fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 18:39:48 +0000 Subject: [PATCH 2/6] Remove duplication --- .../clang-tidy/checks/modernize/use-equals-delete.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst index 47de4185667a3e..a1fab68b0951b9 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst @@ -10,14 +10,11 @@ private function) or a linker error (undefined reference). After C++11, the more idiomatic way to achieve this is by marking the functions as ``= delete``, and keeping them in the ``public`` section. -This check marks unimplemented private special member functions with ``= delete``. -Additionally, it warns about ``delete``'d functions still kept in the ``private`` -section, that should be moved to the ``public`` one instead. - +This check warns only on unimplemented private **special member functions**. To avoid false-positives, this check only applies in a translation unit that has all other member functions implemented. The check will generate partial fixes -by adding ``= delete``, but the user must manually move it to the ``public`` -section. +by adding ``= delete``, but the move the ``public`` section needs to be done +manually. .. code-block:: c++ >From 63ad78a7e313761c627fb68245e56ccac41e86e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 18:49:49 +0000 Subject: [PATCH 3/6] Apply suggestions --- .../checks/modernize/use-equals-delete.rst | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst index a1fab68b0951b9..45039858fffdd3 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst @@ -3,20 +3,26 @@ modernize-use-equals-delete =========================== -Prior to C++11, the only way to "delete" a given function was to make it -``private`` and without definition, to generate a compiler error (calling -private function) or a linker error (undefined reference). - -After C++11, the more idiomatic way to achieve this is by marking the functions -as ``= delete``, and keeping them in the ``public`` section. - -This check warns only on unimplemented private **special member functions**. -To avoid false-positives, this check only applies in a translation unit that has -all other member functions implemented. The check will generate partial fixes -by adding ``= delete``, but the move the ``public`` section needs to be done -manually. - -.. code-block:: c++ +Identifies unimplemented private special member functions, and recommends using +``= delete`` for them, as well as relocating them from the ``private`` to the +``public`` section. + +Before the introduction of C11, 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 C11, 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 { >From 5d4cd44746ce2a6a443493e39523ccee66f1a099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 18:50:33 +0000 Subject: [PATCH 4/6] Fix typo --- .../docs/clang-tidy/checks/modernize/use-equals-delete.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst index 45039858fffdd3..7b1b2a8cee65b4 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst @@ -7,13 +7,13 @@ Identifies unimplemented private special member functions, and recommends using ``= delete`` for them, as well as relocating them from the ``private`` to the ``public`` section. -Before the introduction of C11, the primary method to effectively "erase" a +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 C11, a more conventional approach emerged +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. >From 5b5f851d7cd07be7ff69cb670fcb6d673e987f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 18:52:09 +0000 Subject: [PATCH 5/6] Use C++ for syntax highlighting --- .../docs/clang-tidy/checks/modernize/use-equals-delete.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst index 7b1b2a8cee65b4..6bf1731613bb57 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst @@ -22,7 +22,7 @@ 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 +.. code-block:: c++ // Example: bad class A { >From 3a27a2517151e14d03c648da3a64980e5605973d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Sun, 3 Sep 2023 19:07:22 +0000 Subject: [PATCH 6/6] Sync doc with code --- .../modernize/UseEqualsDeleteCheck.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h index 7870e18e09279c..7dff397c015d9d 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h @@ -13,22 +13,9 @@ namespace clang::tidy::modernize { -/// Mark unimplemented private special member functions with '= delete'. -/// \code -/// struct A { -/// private: -/// A(const A&); -/// A& operator=(const A&); -/// }; -/// \endcode -/// Is converted to: -/// \code -/// struct A { -/// private: -/// A(const A&) = delete; -/// A& operator=(const A&) = delete; -/// }; -/// \endcode +/// Identifies unimplemented private special member functions, and recommends +/// using ``= delete`` for them, as well as relocating them from the ``private`` +/// to the ``public`` section. /// /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-delete.html _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits