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 @@ -383,18 +383,17 @@ } std::vector take() && { + // We only use the Loc to do the comparsion as a location can refer + // to different declarations, e.g. usingDecl refers to overload functions. llvm::sort(References, [](const Reference &L, const Reference &R) { - return std::tie(L.Loc, L.CanonicalTarget, L.Role) < - std::tie(R.Loc, R.CanonicalTarget, R.Role); + return L.Loc < R.Loc; }); // We sometimes see duplicates when parts of the AST get traversed twice. - References.erase( - std::unique(References.begin(), References.end(), - [](const Reference &L, const Reference &R) { - return std::tie(L.CanonicalTarget, L.Loc, L.Role) == - std::tie(R.CanonicalTarget, R.Loc, R.Role); - }), - References.end()); + References.erase(std::unique(References.begin(), References.end(), + [](const Reference &L, const Reference &R) { + return L.Loc == R.Loc; + }), + References.end()); return std::move(References); } 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 @@ -2037,35 +2037,36 @@ TEST(FindReferences, ExplicitSymbols) { const char *Tests[] = { R"cpp( - struct Foo { Foo* [self]() const; }; + struct Foo { Foo* [[self]]() const; }; void f() { - if (Foo* T = foo.[^self]()) {} // Foo member call expr. + Foo foo; + if (Foo* T = foo.[[^self]]()) {} // Foo member call expr. } )cpp", R"cpp( struct Foo { Foo(int); }; Foo f() { - int [b]; - return [^b]; // Foo constructor expr. + int [[b]]; + return [[^b]]; // Foo constructor expr. } )cpp", R"cpp( struct Foo {}; void g(Foo); - Foo [f](); + Foo [[f]](); void call() { - g([^f]()); // Foo constructor expr. + g([[^f]]()); // Foo constructor expr. } )cpp", R"cpp( - void [foo](int); - void [foo](double); + void [[foo]](int); + void [[foo]](double); namespace ns { - using ::[fo^o]; + using ::[[fo^o]]; } )cpp", }; @@ -2075,6 +2076,7 @@ std::vector> ExpectedLocations; for (const auto &R : T.ranges()) ExpectedLocations.push_back(RangeIs(R)); + ASSERT_TRUE(!ExpectedLocations.empty()) << "Testcase must provide ranges!"; EXPECT_THAT(findReferences(AST, T.point(), 0), ElementsAreArray(ExpectedLocations)) << Test;