File tree Expand file tree Collapse file tree 2 files changed +27
-25
lines changed Expand file tree Collapse file tree 2 files changed +27
-25
lines changed Original file line number Diff line number Diff line change 13
13
14
14
namespace clang ::tidy::modernize {
15
15
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.
32
19
// /
33
20
// / For the user-facing documentation see:
34
21
// / http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-delete.html
Original file line number Diff line number Diff line change 3
3
modernize-use-equals-delete
4
4
===========================
5
5
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.
9
24
10
25
.. code-block :: c++
11
26
12
- struct A {
13
- private:
27
+ // Example: bad
28
+ class A {
29
+ private:
14
30
A(const A&);
15
31
A& operator=(const A&);
16
32
};
17
33
18
- // becomes
19
-
20
- struct A {
21
- private:
34
+ // Example: good
35
+ class A {
36
+ public:
22
37
A(const A&) = delete;
23
38
A& operator=(const A&) = delete;
24
39
};
You can’t perform that action at this time.
0 commit comments