File tree Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ void CrtpConstructorAccessibilityCheck::check(
157
157
}
158
158
159
159
for (auto &&Ctor : CRTPDeclaration->ctors ()) {
160
- if (Ctor->getAccess () == AS_private)
160
+ if (Ctor->getAccess () == AS_private || Ctor-> isDeleted () )
161
161
continue ;
162
162
163
163
const bool IsPublic = Ctor->getAccess () == AS_public;
Original file line number Diff line number Diff line change @@ -148,6 +148,11 @@ New check aliases
148
148
Changes in existing checks
149
149
^^^^^^^^^^^^^^^^^^^^^^^^^^
150
150
151
+ - Improved :doc: `bugprone-crtp-constructor-accessibility
152
+ <clang-tidy/checks/bugprone/crtp-constructor-accessibility>` check by fixing
153
+ false positives on deleted constructors that cannot be used to construct
154
+ objects, even if they have public or protected access.
155
+
151
156
- Improved :doc: `bugprone-optional-value-conversion
152
157
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
153
158
conversion in argument of ``std::make_optional ``.
Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ Example:
65
65
To ensure that no accidental instantiation happens, the best practice is to
66
66
make the constructor private and declare the derived class as friend. Note
67
67
that as a tradeoff, this also gives the derived class access to every other
68
- private members of the CRTP.
68
+ private members of the CRTP. However, constructors can still be public or
69
+ protected if they are deleted.
69
70
70
71
Example:
71
72
Original file line number Diff line number Diff line change @@ -253,3 +253,34 @@ void foo() {
253
253
(void ) A;
254
254
}
255
255
} // namespace no_warning_unsupported
256
+
257
+ namespace public_copy_move_constructors_deleted {
258
+ template <typename T>
259
+ class CRTP
260
+ {
261
+ CRTP () = default ;
262
+ friend T;
263
+ public:
264
+ CRTP (const CRTP&) = delete ;
265
+ CRTP (CRTP&&) = delete ;
266
+ };
267
+
268
+ class A : CRTP<A> {};
269
+
270
+ } // namespace public_copy_move_constructors_deleted
271
+
272
+ namespace public_copy_protected_move_constructor_deleted {
273
+ template <typename T>
274
+ class CRTP
275
+ {
276
+ CRTP () = default ;
277
+ friend T;
278
+ public:
279
+ CRTP (const CRTP&) = delete ;
280
+ protected:
281
+ CRTP (CRTP&&) = delete ;
282
+ };
283
+
284
+ class A : CRTP<A> {};
285
+
286
+ } // namespace public_copy_protected_move_constructor_deleted
You can’t perform that action at this time.
0 commit comments