Skip to content
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

[clang-tidy] bugprone-unhandled-self-assignment: fix smart pointer check against std::unique_ptr type #121266

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -74,9 +74,11 @@ void UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
// Matcher for standard smart pointers.
const auto SmartPointerType = qualType(hasUnqualifiedDesugaredType(
recordType(hasDeclaration(classTemplateSpecializationDecl(
hasAnyName("::std::shared_ptr", "::std::unique_ptr",
"::std::weak_ptr", "::std::auto_ptr"),
templateArgumentCountIs(1))))));
anyOf(allOf(hasAnyName("::std::shared_ptr", "::std::weak_ptr",
"::std::auto_ptr"),
templateArgumentCountIs(1)),
allOf(hasName("::std::unique_ptr"),
templateArgumentCountIs(2))))))));

// We will warn only if the class has a pointer or a C array field which
// probably causes a problem during self-assignment (e.g. first resetting
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ Changes in existing checks
`bsl::optional` and `bdlb::NullableValue` from
<https://github.com/bloomberg/bde>_.

- Improved :doc:`bugprone-unhandled-self-assignment
<clang-tidy/checks/bugprone/unhandled-self-assignment>` check by fixing smart
pointer check against std::unique_ptr type.

- Improved :doc:`bugprone-unsafe-functions
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
additional functions to match.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ template <class T>
T &&move(T &x) {
}

template <class T>
template <typename T> class default_delete {};

template <class T, typename Deleter = std::default_delete<T>>
class unique_ptr {
};

Expand Down
Loading