[clang-tools-extra] [clangd] Fix erroneous qualification of template type parameters (PR #116821)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 07:06:57 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clangd
Author: Christian Kandeler (ckandeler)
<details>
<summary>Changes</summary>
...in DefineOutline tweak.
E.g. moving the following definition:
template<typename T> struct S { T f^oo() const { return T(); } };
would result in:
// ...
template<typename T> S<T>::T S::foo() const { return T(); }
instead of:
template<typename T> T S::foo() const { return T(); }
---
Full diff: https://github.com/llvm/llvm-project/pull/116821.diff
2 Files Affected:
- (modified) clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp (+2)
- (modified) clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp (+6-6)
``````````diff
diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index 2a96b305bd7a25..789c10bdd4822a 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -239,6 +239,8 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext,
return;
for (const NamedDecl *ND : Ref.Targets) {
+ if (ND->getKind() == Decl::TemplateTypeParm)
+ return;
if (ND->getDeclContext() != Ref.Targets.front()->getDeclContext()) {
elog("Targets from multiple contexts: {0}, {1}",
printQualifiedName(*Ref.Targets.front()),
diff --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
index 1af1bc31bf6486..d2d2ae9e7bb610 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -411,14 +411,14 @@ inline typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>
R"cpp(
struct Foo {
template <typename T, bool B = true>
- void ^bar() {}
+ T ^bar() { return {}; }
};)cpp",
R"cpp(
struct Foo {
template <typename T, bool B = true>
- void bar() ;
+ T bar() ;
};template <typename T, bool B>
-inline void Foo::bar() {}
+inline T Foo::bar() { return {}; }
)cpp",
""},
@@ -426,14 +426,14 @@ inline void Foo::bar() {}
{
R"cpp(
template <typename T> struct Foo {
- template <typename U> void ^bar(const T& t, const U& u) {}
+ template <typename U> T ^bar(const T& t, const U& u) { return {}; }
};)cpp",
R"cpp(
template <typename T> struct Foo {
- template <typename U> void bar(const T& t, const U& u) ;
+ template <typename U> T bar(const T& t, const U& u) ;
};template <typename T>
template <typename U>
-inline void Foo<T>::bar(const T& t, const U& u) {}
+inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
)cpp",
""},
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/116821
More information about the cfe-commits
mailing list