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

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 01:23:54 PDT 2023


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))));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148418.513859.patch
Type: text/x-patch
Size: 2051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230415/7dbbbdc3/attachment-0001.bin>


More information about the cfe-commits mailing list