Skip to content

Commit fdb6e8b

Browse files
carlosgalvezpCarlos Gálvez
andauthored
[clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (#65231)
…-delete So the purpose of the check is more clear. Update examples code to show compliant code. Fixes #65221 --------- Co-authored-by: Carlos Gálvez <[email protected]>
1 parent 6098d7d commit fdb6e8b

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,9 @@
1313

1414
namespace clang::tidy::modernize {
1515

16-
/// Mark unimplemented private special member functions with '= delete'.
17-
/// \code
18-
/// struct A {
19-
/// private:
20-
/// A(const A&);
21-
/// A& operator=(const A&);
22-
/// };
23-
/// \endcode
24-
/// Is converted to:
25-
/// \code
26-
/// struct A {
27-
/// private:
28-
/// A(const A&) = delete;
29-
/// A& operator=(const A&) = delete;
30-
/// };
31-
/// \endcode
16+
/// Identifies unimplemented private special member functions, and recommends
17+
/// using ``= delete`` for them. Additionally, it recommends relocating any
18+
/// deleted member function from the ``private`` to the ``public`` section.
3219
///
3320
/// For the user-facing documentation see:
3421
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-delete.html

clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,37 @@
33
modernize-use-equals-delete
44
===========================
55

6-
This check marks unimplemented private special member functions with ``= delete``.
7-
To avoid false-positives, this check only applies in a translation unit that has
8-
all other member functions implemented.
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.
924

1025
.. code-block:: c++
1126

12-
struct A {
13-
private:
27+
// Example: bad
28+
class A {
29+
private:
1430
A(const A&);
1531
A& operator=(const A&);
1632
};
1733

18-
// becomes
19-
20-
struct A {
21-
private:
34+
// Example: good
35+
class A {
36+
public:
2237
A(const A&) = delete;
2338
A& operator=(const A&) = delete;
2439
};

0 commit comments

Comments
 (0)