From 827f49e3faf59f99082d0085de06dcbc09be8ba3 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 30 Jan 2020 12:45:43 +0100 Subject: [PATCH] [clangd] Make go-to-def jumps to overriden methods on `final` specifier. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73690 --- clang-tools-extra/clangd/XRefs.cpp | 5 ++++- clang-tools-extra/clangd/unittests/XRefsTests.cpp | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index b302a0d..61dff3e 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -22,6 +22,7 @@ #include "index/SymbolLocation.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" +#include "clang/AST/Attrs.inc" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" @@ -277,7 +278,9 @@ std::vector locateSymbolAt(ParsedAST &AST, Position Pos, for (const NamedDecl *D : getDeclAtPosition(AST, SourceLoc, Relations)) { // Special case: void foo() ^override: jump to the overridden method. if (const auto *CMD = llvm::dyn_cast(D)) { - const auto *Attr = D->getAttr(); + const InheritableAttr* Attr = D->getAttr(); + if (!Attr) + Attr = D->getAttr(); const syntax::Token *Tok = spelledIdentifierTouching(SourceLoc, AST.getTokens()); if (Attr && Tok && diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp index 3486139..2262139 100644 --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -452,6 +452,11 @@ TEST(LocateSymbol, All) { class X : Y { void a() ^override {} }; )cpp", + R"cpp(// Final specifier jumps to overridden method + class Y { virtual void $decl[[a]]() = 0; }; + class X : Y { void a() ^final {} }; + )cpp", + R"cpp(// Heuristic resolution of dependent method template struct S { -- 2.7.4