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(
157157 }
158158
159159 for (auto &&Ctor : CRTPDeclaration->ctors ()) {
160- if (Ctor->getAccess () == AS_private)
160+ if (Ctor->getAccess () == AS_private || Ctor-> isDeleted () )
161161 continue ;
162162
163163 const bool IsPublic = Ctor->getAccess () == AS_public;
Original file line number Diff line number Diff line change @@ -148,6 +148,11 @@ New check aliases
148148Changes in existing checks
149149^^^^^^^^^^^^^^^^^^^^^^^^^^
150150
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+
151156- Improved :doc: `bugprone-optional-value-conversion
152157 <clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
153158 conversion in argument of ``std::make_optional ``.
Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ Example:
6565To ensure that no accidental instantiation happens, the best practice is to
6666make the constructor private and declare the derived class as friend. Note
6767that 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.
6970
7071Example:
7172
Original file line number Diff line number Diff line change @@ -253,3 +253,34 @@ void foo() {
253253 (void ) A;
254254}
255255} // 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