diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/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(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); + } } } } diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/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); }