[clangd] Make go-to-def jumps to overriden methods on `final` specifier.
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 30 Jan 2020 11:45:43 +0000 (12:45 +0100)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 30 Jan 2020 11:49:30 +0000 (12:49 +0100)
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
clang-tools-extra/clangd/unittests/XRefsTests.cpp

index b302a0d..61dff3e 100644 (file)
@@ -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<LocatedSymbol> 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<CXXMethodDecl>(D)) {
-      const auto *Attr = D->getAttr<OverrideAttr>();
+      const InheritableAttr* Attr = D->getAttr<OverrideAttr>();
+      if (!Attr)
+        Attr = D->getAttr<FinalAttr>();
       const syntax::Token *Tok =
           spelledIdentifierTouching(SourceLoc, AST.getTokens());
       if (Attr && Tok &&
index 3486139..2262139 100644 (file)
@@ -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 <typename T>
         struct S {