[clangd] Unwrap type sugar in HeuristicResolver::resolveTypeToRecordDecl()
authorNathan Ridge <zeratul976@hotmail.com>
Fri, 9 Jun 2023 06:39:28 +0000 (02:39 -0400)
committerNathan Ridge <zeratul976@hotmail.com>
Wed, 14 Jun 2023 17:51:00 +0000 (13:51 -0400)
Fixes https://github.com/clangd/clangd/issues/1663

Differential Revision: https://reviews.llvm.org/D152500

clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

index 460b9be..e91bd0e 100644 (file)
@@ -35,6 +35,9 @@ const auto TemplateFilter = [](const NamedDecl *D) {
 CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
   assert(T);
 
+  // Unwrap type sugar such as type aliases.
+  T = T->getCanonicalTypeInternal().getTypePtr();
+
   if (const auto *RT = T->getAs<RecordType>())
     return dyn_cast<CXXRecordDecl>(RT->getDecl());
 
index fe87e4b..d54539b 100644 (file)
@@ -863,6 +863,20 @@ TEST_F(TargetDeclTest, DependentExprs) {
       )cpp";
   EXPECT_DECLS("CXXDependentScopeMemberExpr",
                "template <typename T> T convert() const");
+
+  Code = R"cpp(
+        template <typename T>
+        struct Waldo {
+          void find();
+        };
+        template <typename T>
+        using Wally = Waldo<T>;
+        template <typename T>
+        void foo(Wally<T> w) {
+          w.[[find]]();
+        }
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void find()");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {