[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

Utkarsh Saxena via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 5 08:40:02 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6831c1d8689b: [clangd] Include refs of base method in refs for derived method. (authored by usaxena95).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111039/new/

https://reviews.llvm.org/D111039

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@
         AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
                                    ReferencesResult::Definition |
                                    ReferencesResult::Override)));
-  EXPECT_THAT(
-      findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-          .References,
-      UnorderedElementsAreArray(ExpectedLocations))
-      << Test;
+  for (const auto &P : T.points()) {
+    EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr)
+                    .References,
+                UnorderedElementsAreArray(ExpectedLocations))
+        << "Failed for Refs at " << P << "\n"
+        << Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@
       R"cpp(
         class Base {
         public:
-          virtual void $decl[[f^unc]]() = 0;
+          virtu^al void $decl[[f^unc]]() ^= ^0;
         };
         class Derived : public Base {
         public:
@@ -1990,13 +1992,13 @@
         };
         class Derived : public Base {
         public:
-          void $decl[[fu^nc]]() override;
+          void $decl[[fu^nc]]() over^ride;
         };
         void test(BaseBase* BB, Base* B, Derived* D) {
           // refs to overridden methods in complete type hierarchy are reported.
           BB->[[func]]();
           B->[[func]]();
-          D->[[func]]();
+          D->[[fu^nc]]();
         })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1391,13 +1391,11 @@
         // Special case: For virtual methods, report decl/def of overrides and
         // references to all overridden methods in complete type hierarchy.
         if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(ND)) {
-          if (CMD->isVirtual())
-            if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-                                          IdentifierAtCursor->location()) {
-              if (auto ID = getSymbolID(CMD))
-                OverriddenBy.Subjects.insert(ID);
-              getOverriddenMethods(CMD, OverriddenMethods);
-            }
+          if (CMD->isVirtual()) {
+            if (auto ID = getSymbolID(CMD))
+              OverriddenBy.Subjects.insert(ID);
+            getOverriddenMethods(CMD, OverriddenMethods);
+          }
         }
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111039.377265.patch
Type: text/x-patch
Size: 2740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211005/5aa57e7f/attachment.bin>


More information about the cfe-commits mailing list