Skip to content

[clang-tidy] Fix false positives in bugprone-crtp-constructor-accessibility check #132543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void CrtpConstructorAccessibilityCheck::check(
}

for (auto &&Ctor : CRTPDeclaration->ctors()) {
if (Ctor->getAccess() == AS_private)
if (Ctor->getAccess() == AS_private || Ctor->isDeleted())
continue;

const bool IsPublic = Ctor->getAccess() == AS_public;
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ New check aliases
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^

- Improved :doc:`bugprone-crtp-constructor-accessibility
<clang-tidy/checks/bugprone/crtp-constructor-accessibility>` check by fixing
false positives on deleted constructors that cannot be used to construct
objects, even if they have public or protected access.

- Improved :doc:`bugprone-optional-value-conversion
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
conversion in argument of ``std::make_optional``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Example:
To ensure that no accidental instantiation happens, the best practice is to
make the constructor private and declare the derived class as friend. Note
that as a tradeoff, this also gives the derived class access to every other
private members of the CRTP.
private members of the CRTP. However, constructors can still be public or
protected if they are deleted.

Example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,34 @@ void foo() {
(void) A;
}
} // namespace no_warning_unsupported

namespace public_copy_move_constructors_deleted {
template <typename T>
class CRTP
{
CRTP() = default;
friend T;
public:
CRTP(const CRTP&) = delete;
CRTP(CRTP&&) = delete;
};

class A : CRTP<A> {};

} // namespace public_copy_move_constructors_deleted

namespace public_copy_protected_move_constructor_deleted {
template <typename T>
class CRTP
{
CRTP() = default;
friend T;
public:
CRTP(const CRTP&) = delete;
protected:
CRTP(CRTP&&) = delete;
};

class A : CRTP<A> {};

} // namespace public_copy_protected_move_constructor_deleted
Loading