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>`


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>`
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to