[clang-tidy] Fix typedefs handling in bugprone-dangling-handle

Using 'hasUnqualifiedDesugaredType' to skip all type aliases when
checking for handle.

Fixes #38779

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D148418
This commit is contained in:
Piotr Zegar 2023-04-15 10:29:38 +00:00
parent 9a888c7679
commit 35f466eb14
3 changed files with 9 additions and 2 deletions

View File

@ -25,7 +25,8 @@ handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
return expr(
anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
hasArgument(0, Arg)),
cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
hasDeclaration(cxxRecordDecl(IsAHandle))))),
callee(memberExpr(member(cxxConversionDecl()))),
on(Arg))));
}

View File

@ -174,6 +174,10 @@ Changes in existing checks
arguments to ``std::print``, ``std::format`` or other functions listed in
the ``StringParameterFunction`` check option.
- Improved :doc:`bugprone-dangling-handle
<clang-tidy/checks/bugprone/dangling-handle>` check enhancing detection of
handles behind type aliases.
- Deprecated check-local options `HeaderFileExtensions`
in :doc:`bugprone-dynamic-static-initializers
<clang-tidy/checks/bugprone/dynamic-static-initializers>` check.

View File

@ -52,7 +52,8 @@ class basic_string {
basic_string();
basic_string(const char*);
operator basic_string_view() const noexcept;
typedef basic_string_view str_view;
operator str_view() const noexcept;
~basic_string();
};
@ -193,3 +194,4 @@ void Negatives(std::string_view default_arg = ReturnsAString()) {
TakesAStringView(std::string());
}