Skip to content

Commit 5310855

Browse files
authored
[clangd] Fix erroneous qualification of template type parameters (#116821)
...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(); }`
1 parent 3488113 commit 5310855

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext,
239239
return;
240240

241241
for (const NamedDecl *ND : Ref.Targets) {
242+
if (ND->getKind() == Decl::TemplateTypeParm)
243+
return;
242244
if (ND->getDeclContext() != Ref.Targets.front()->getDeclContext()) {
243245
elog("Targets from multiple contexts: {0}, {1}",
244246
printQualifiedName(*Ref.Targets.front()),

clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,29 +411,29 @@ inline typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>
411411
R"cpp(
412412
struct Foo {
413413
template <typename T, bool B = true>
414-
void ^bar() {}
414+
T ^bar() { return {}; }
415415
};)cpp",
416416
R"cpp(
417417
struct Foo {
418418
template <typename T, bool B = true>
419-
void bar() ;
419+
T bar() ;
420420
};template <typename T, bool B>
421-
inline void Foo::bar() {}
421+
inline T Foo::bar() { return {}; }
422422
)cpp",
423423
""},
424424

425425
// Class template with member template
426426
{
427427
R"cpp(
428428
template <typename T> struct Foo {
429-
template <typename U> void ^bar(const T& t, const U& u) {}
429+
template <typename U> T ^bar(const T& t, const U& u) { return {}; }
430430
};)cpp",
431431
R"cpp(
432432
template <typename T> struct Foo {
433-
template <typename U> void bar(const T& t, const U& u) ;
433+
template <typename U> T bar(const T& t, const U& u) ;
434434
};template <typename T>
435435
template <typename U>
436-
inline void Foo<T>::bar(const T& t, const U& u) {}
436+
inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
437437
)cpp",
438438
""},
439439
};

0 commit comments

Comments
 (0)