[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
This commit is contained in:
Haojian Wu 2020-01-30 12:45:43 +01:00
parent 2692751895
commit 827f49e3fa
2 changed files with 9 additions and 1 deletions

View 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 &&

View 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 {