diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp index 11299b9403076..82c07bdc2ba95 100644 --- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp @@ -25,7 +25,8 @@ handleFrom(const ast_matchers::internal::Matcher &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)))); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 7536aba58af50..fabd7f35a7577 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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 + ` check enhancing detection of + handles behind type aliases. + - Deprecated check-local options `HeaderFileExtensions` in :doc:`bugprone-dynamic-static-initializers ` check. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp index 349875a3c99cd..5751b3d967a2c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp @@ -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()); } +