[clang-tools-extra] [clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (PR #65231)

Carlos Galvez via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 00:59:54 PDT 2023


Carlos =?utf-8?q?Gálvez?= <carlos.galvez at zenseact.com>,
Carlos =?utf-8?q?Gálvez?= <carlos.galvez at zenseact.com>,
Carlos =?utf-8?q?Gálvez?= <carlos.galvez at zenseact.com>,
Carlos =?utf-8?q?Gálvez?= <carlos.galvez at zenseact.com>,
Carlos =?utf-8?q?Gálvez?= <carlos.galvez at zenseact.com>,
Carlos =?utf-8?q?Gálvez?= <carlos.galvez at 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 18:24:55 +0000
Subject: [PATCH 1/7] [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 c3de904e2538021..47de4185667a3ea 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 18:39:48 +0000
Subject: [PATCH 2/7] 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 47de4185667a3ea..a1fab68b0951b9d 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 18:49:49 +0000
Subject: [PATCH 3/7] 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 a1fab68b0951b9d..45039858fffdd3b 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 18:50:33 +0000
Subject: [PATCH 4/7] 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 45039858fffdd3b..7b1b2a8cee65b4a 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 18:52:09 +0000
Subject: [PATCH 5/7] 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 7b1b2a8cee65b4a..6bf1731613bb570 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.galvez at zenseact.com>
Date: Sun, 3 Sep 2023 19:07:22 +0000
Subject: [PATCH 6/7] 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 7870e18e09279c7..7dff397c015d9d9 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

>From 11372e0789eea4f11a888a75f4e1af63f37826d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.galvez at zenseact.com>
Date: Mon, 4 Sep 2023 07:59:41 +0000
Subject: [PATCH 7/7] Improve doc about relocating functions

---
 clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h | 4 ++--
 .../docs/clang-tidy/checks/modernize/use-equals-delete.rst    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
index 7dff397c015d9d9..8478a0146f3089e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
@@ -14,8 +14,8 @@
 namespace clang::tidy::modernize {
 
 /// Identifies unimplemented private special member functions, and recommends
-/// using ``= delete`` for them, as well as relocating them from the ``private``
-/// to the ``public`` section.
+/// using ``= delete`` for them. Additionally, it recommends relocating any
+/// deleted member function 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
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 6bf1731613bb570..d354fcc6060ce29 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
@@ -4,8 +4,8 @@ modernize-use-equals-delete
 ===========================
 
 Identifies unimplemented private special member functions, and recommends using
-``= delete`` for them, as well as relocating them from the ``private`` to the
-``public`` section.
+``= 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



More information about the cfe-commits mailing list