diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp --- a/clang-tools-extra/clangd/refactor/Rename.cpp +++ b/clang-tools-extra/clangd/refactor/Rename.cpp @@ -74,6 +74,10 @@ const SymbolIndex *Index) { if (llvm::isa(&RenameDecl)) return ReasonToReject::UnsupportedSymbol; + if (const auto *FD = llvm::dyn_cast(&RenameDecl)) { + if (FD->isOverloadedOperator()) + return ReasonToReject::UnsupportedSymbol; + } auto &ASTCtx = RenameDecl.getASTContext(); const auto &SM = ASTCtx.getSourceManager(); bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile; diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp --- a/clang-tools-extra/clangd/unittests/RenameTests.cpp +++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -136,9 +136,17 @@ )cpp", "not a supported kind", HeaderFile}, + { + + R"cpp( + struct X { X operator++(int) {} }; + void f(X x) {x+^+;})cpp", + "not a supported kind", HeaderFile}, + {R"cpp(// foo is declared outside the file. void fo^o() {} - )cpp", "used outside main file", !HeaderFile/*cc file*/}, + )cpp", + "used outside main file", !HeaderFile/*cc file*/}, }; const char *CommonHeader = R"cpp( class Outside {}; diff --git a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h --- a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h +++ b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h @@ -122,8 +122,7 @@ ND, SourceRange(BeginLoc, EndLoc)); } bool visit(const NamedDecl *ND, SourceLocation Loc) { - return visit(ND, Loc, - Loc.getLocWithOffset(ND->getNameAsString().length() - 1)); + return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts)); } };