From 011732852c2c1ca1015fac1bed831308dc521583 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Wed, 5 Aug 2020 13:34:05 +0200 Subject: [PATCH] [clangd] Fix a crash in DefineInline Differential Revision: https://reviews.llvm.org/D85291 --- clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp | 2 +- clang-tools-extra/clangd/unittests/TweakTests.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp index e28a2c46c374a..698d2a406811a 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp @@ -339,7 +339,7 @@ renameParameters(const FunctionDecl *Dest, const FunctionDecl *Source) { // specialization. const FunctionDecl *findTarget(const FunctionDecl *FD) { auto CanonDecl = FD->getCanonicalDecl(); - if (!FD->isFunctionTemplateSpecialization()) + if (!FD->isFunctionTemplateSpecialization() || CanonDecl == FD) return CanonDecl; // For specializations CanonicalDecl is the TemplatedDecl, which is not the // target we want to inline into. Instead we traverse previous decls to find diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp index 319d9e088c2d8..7919651600552 100644 --- a/clang-tools-extra/clangd/unittests/TweakTests.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -1093,6 +1093,11 @@ TEST_F(DefineInlineTest, TemplateSpec) { template<> void f^oo() { bar(); })cpp"); + EXPECT_UNAVAILABLE(R"cpp( + namespace bar { + template void f^oo() {} + template void foo(); + })cpp"); } TEST_F(DefineInlineTest, CheckForCanonDecl) {