[PATCH] D141608: [include-cleaner] Don't consider the underlying type of Decltype MemberProvider as a use

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 12 06:04:36 PST 2023


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

For this case, the argument of `decltype` is the provider.

This fixes the sample in https://github.com/llvm/llvm-project/issues/59916#issuecomment-1377214667


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141608

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -229,6 +229,7 @@
       namespace ns { template<typename> struct Foo { int a; }; }
       using ns::$implicit^Foo;)cpp",
            "void k(Foo<int> b) { b.^a; }");
+  testWalk("struct Foo { int a; };", "void test(decltype(Foo()) b) { b.^a; }");
   // Test the dependent-type case (CXXDependentScopeMemberExpr)
   testWalk("template<typename T> struct $implicit^Base { void method(); };",
            "template<typename T> void k(Base<T> t) { t.^method(); }");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -51,6 +51,10 @@
       return TT->getDecl();
     if (const auto *UT = dyn_cast<UsingType>(Base))
       return UT->getFoundDecl();
+    // Don't consider the underlying type of the decltype as a use (generally
+    // the argument of decltype should provide them).
+    if (const auto *DT = dyn_cast<DecltypeType>(Base))
+      return nullptr;
     // A heuristic: to resolve a template type to **only** its template name.
     // We're only using this method for the base type of MemberExpr, in general
     // the template provides the member, and the critical case `unique_ptr<Foo>`


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141608.488628.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230112/e6243906/attachment.bin>


More information about the cfe-commits mailing list