This revision was automatically updated to reflect the committed changes. hokein marked an inline comment as done. Closed by commit rGaf28bb65023e: [clangd] Fix a crash when renaming operator. (authored by hokein). Herald added a subscriber: usaxena95.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67607/new/ https://reviews.llvm.org/D67607 Files: clang-tools-extra/clangd/refactor/Rename.cpp clang-tools-extra/clangd/unittests/RenameTests.cpp clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h =================================================================== --- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h +++ 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)); } }; Index: clang-tools-extra/clangd/unittests/RenameTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/RenameTests.cpp +++ clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -136,6 +136,13 @@ )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*/}, Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -74,6 +74,10 @@ const SymbolIndex *Index) { if (llvm::isa<NamespaceDecl>(&RenameDecl)) return ReasonToReject::UnsupportedSymbol; + if (const auto *FD = llvm::dyn_cast<FunctionDecl>(&RenameDecl)) { + if (FD->isOverloadedOperator()) + return ReasonToReject::UnsupportedSymbol; + } auto &ASTCtx = RenameDecl.getASTContext(); const auto &SM = ASTCtx.getSourceManager(); bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h =================================================================== --- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h +++ 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)); } }; Index: clang-tools-extra/clangd/unittests/RenameTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/RenameTests.cpp +++ clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -136,6 +136,13 @@ )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*/}, Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -74,6 +74,10 @@ const SymbolIndex *Index) { if (llvm::isa<NamespaceDecl>(&RenameDecl)) return ReasonToReject::UnsupportedSymbol; + if (const auto *FD = llvm::dyn_cast<FunctionDecl>(&RenameDecl)) { + if (FD->isOverloadedOperator()) + return ReasonToReject::UnsupportedSymbol; + } auto &ASTCtx = RenameDecl.getASTContext(); const auto &SM = ASTCtx.getSourceManager(); bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits