[PATCH] D110324: clangd: Do not report inline overrides twice

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 23 07:09:30 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb209c13cce9: clangd: Do not report inline overrides twice (authored by ckandeler, committed by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110324

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
@@ -1947,6 +1947,9 @@
           void $overridedecl[[func]]() override;
         };
         void Derived::$overridedef[[func]]() {}
+        class Derived2 : public Base {
+          void $overridedef[[func]]() override {}
+        };
         void test(Derived* D) {
           D->func();  // No references to the overrides.
         })cpp";
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1431,17 +1431,20 @@
         !OverriddenBy.Subjects.empty())
       Index->relations(
           OverriddenBy, [&](const SymbolID &Subject, const Symbol &Object) {
-            if (auto LSPLoc =
-                    toLSPLocation(Object.CanonicalDeclaration, *MainFilePath)) {
+            const auto LSPLocDecl =
+                toLSPLocation(Object.CanonicalDeclaration, *MainFilePath);
+            const auto LSPLocDef =
+                toLSPLocation(Object.Definition, *MainFilePath);
+            if (LSPLocDecl && LSPLocDecl != LSPLocDef) {
               ReferencesResult::Reference Result;
-              Result.Loc = std::move(*LSPLoc);
+              Result.Loc = std::move(*LSPLocDecl);
               Result.Attributes =
                   ReferencesResult::Declaration | ReferencesResult::Override;
               Results.References.push_back(std::move(Result));
             }
-            if (auto LSPLoc = toLSPLocation(Object.Definition, *MainFilePath)) {
+            if (LSPLocDef) {
               ReferencesResult::Reference Result;
-              Result.Loc = std::move(*LSPLoc);
+              Result.Loc = std::move(*LSPLocDef);
               Result.Attributes = ReferencesResult::Declaration |
                                   ReferencesResult::Definition |
                                   ReferencesResult::Override;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110324.374534.patch
Type: text/x-patch
Size: 2121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210923/a245ccd1/attachment.bin>


More information about the cfe-commits mailing list