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 @@ -101,12 +101,14 @@ if (const FunctionDecl *InstantiatedMethod = Method->getInstantiatedFromMemberFunction()) return canonicalRenameDecls(InstantiatedMethod); - // FIXME(kirillbobyrev): For virtual methods with - // size_overridden_methods() > 1, this will not rename all functions it - // overrides, because this code assumes there is a single canonical - // declaration. - if (Method->isVirtual() && Method->size_overridden_methods()) - return {canonicalRenameDecls(*Method->overridden_methods().begin())}; + if (Method->isVirtual() && Method->size_overridden_methods()) { + llvm::DenseSet Result; + for (const auto *OM : Method->overridden_methods()) { + auto Decls = canonicalRenameDecls(OM); + Result.insert(Decls.begin(), Decls.end()); + } + return Result; + } } if (const auto *Function = dyn_cast(D)) if (const FunctionTemplateDecl *Template = Function->getPrimaryTemplate()) 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 @@ -1522,26 +1522,32 @@ virtual void [[foo]](); }; class Derived1 : public Base { - void [[f^oo]]() override; + void [[foo]]() override; }; - class NotDerived { - void foo() {}; + class Derived2 : public Base { + void [[foo]]() override; + }; + class DerivedDerived : public Derived1, public Derived2 { + void foo() override; } )cpp", R"cpp( #include "foo.h" void Base::[[foo]]() {} void Derived1::[[foo]]() {} + void Derived2::[[foo]]() {} + void DerivedDerived::[[foo]]() {} - class Derived2 : public Derived1 { + class Derived3 : public Derived1 { void [[foo]]() override {}; }; - void func(Base* b, Derived1* d1, - Derived2* d2, NotDerived* nd) { + void func(Base* b, Derived1* d1, Derived2* d2, + DerivedDerived* dd, NotDerived* nd) { b->[[foo]](); d1->[[foo]](); d2->[[foo]](); + dd->[[foo]](); nd->foo(); } )cpp",