Author: Piotr Zegar Date: 2023-04-15T10:29:39Z New Revision: 35f466eb14b7e57e8bd33a8eb98e89fe3a4cd839
URL: https://github.com/llvm/llvm-project/commit/35f466eb14b7e57e8bd33a8eb98e89fe3a4cd839 DIFF: https://github.com/llvm/llvm-project/commit/35f466eb14b7e57e8bd33a8eb98e89fe3a4cd839.diff LOG: [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 Added: Modified: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp Removed: ################################################################################ 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<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)))); } 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 + <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. 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()); } + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits