PiotrZSL created this revision. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a reviewer: njames93. Herald added a project: All. PiotrZSL requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Using 'hasUnqualifiedDesugaredType' to skip all type aliases when checking for handle. Fixes #38779 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148418 Files: 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 Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp @@ -52,7 +52,8 @@ 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 @@ TakesAStringView(std::string()); } + Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -174,6 +174,10 @@ 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. Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp @@ -25,7 +25,8 @@ 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)))); }
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp @@ -52,7 +52,8 @@ 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 @@ TakesAStringView(std::string()); } + Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -174,6 +174,10 @@ 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. Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp @@ -25,7 +25,8 @@ 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)))); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits