Skip to content

Commit 9acd8e3

Browse files
authored
[clangd] Drop requirement for named template parameters (#117565)
... in DefineOutline tweak for function templates. As opposed to class templates, the name is not required for writing an out-of-line definition.
1 parent a96ec01 commit 9acd8e3

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,18 +467,9 @@ class DefineOutline : public Tweak {
467467
}
468468
}
469469

470-
// For function templates, the same limitations as for class templates
471-
// apply.
472-
if (const TemplateParameterList *Params =
473-
MD->getDescribedTemplateParams()) {
474-
// FIXME: Is this really needed? It inhibits application on
475-
// e.g. std::enable_if.
476-
for (NamedDecl *P : *Params) {
477-
if (!P->getIdentifier())
478-
return false;
479-
}
470+
// Function templates must be defined in the same file.
471+
if (MD->getDescribedTemplate())
480472
SameFile = true;
481-
}
482473

483474
// The refactoring is meaningless for unnamed classes and namespaces,
484475
// unless we're outlining in the same file

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) {
118118
template <> void fo^o<int>() {}
119119
)cpp");
120120

121-
// Not available on member function templates with unnamed template
122-
// parameters.
123-
EXPECT_UNAVAILABLE(R"cpp(
124-
struct Foo { template <typename> void ba^r() {} };
125-
)cpp");
126-
127121
// Not available on methods of unnamed classes.
128122
EXPECT_UNAVAILABLE(R"cpp(
129123
struct Foo {
@@ -410,14 +404,14 @@ inline typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>
410404
{
411405
R"cpp(
412406
struct Foo {
413-
template <typename T, bool B = true>
407+
template <typename T, typename, bool B = true>
414408
T ^bar() { return {}; }
415409
};)cpp",
416410
R"cpp(
417411
struct Foo {
418-
template <typename T, bool B = true>
412+
template <typename T, typename, bool B = true>
419413
T bar() ;
420-
};template <typename T, bool B>
414+
};template <typename T, typename, bool B>
421415
inline T Foo::bar() { return {}; }
422416
)cpp",
423417
""},
@@ -426,13 +420,13 @@ inline T Foo::bar() { return {}; }
426420
{
427421
R"cpp(
428422
template <typename T> struct Foo {
429-
template <typename U> T ^bar(const T& t, const U& u) { return {}; }
423+
template <typename U, bool> T ^bar(const T& t, const U& u) { return {}; }
430424
};)cpp",
431425
R"cpp(
432426
template <typename T> struct Foo {
433-
template <typename U> T bar(const T& t, const U& u) ;
427+
template <typename U, bool> T bar(const T& t, const U& u) ;
434428
};template <typename T>
435-
template <typename U>
429+
template <typename U, bool>
436430
inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
437431
)cpp",
438432
""},

0 commit comments

Comments
 (0)