[clang-tools-extra] 9acd8e3 - [clangd] Drop requirement for named template parameters (#117565)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 01:11:11 PST 2024


Author: Christian Kandeler
Date: 2024-11-26T10:11:07+01:00
New Revision: 9acd8e381091765a932d54bc22359cdafa9e75c6

URL: https://github.com/llvm/llvm-project/commit/9acd8e381091765a932d54bc22359cdafa9e75c6
DIFF: https://github.com/llvm/llvm-project/commit/9acd8e381091765a932d54bc22359cdafa9e75c6.diff

LOG: [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.

Added: 
    

Modified: 
    clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
    clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index 789c10bdd4822a..e4eef228b6b99f 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -467,18 +467,9 @@ class DefineOutline : public Tweak {
       }
     }
 
-    // For function templates, the same limitations as for class templates
-    // apply.
-    if (const TemplateParameterList *Params =
-            MD->getDescribedTemplateParams()) {
-      // FIXME: Is this really needed? It inhibits application on
-      //        e.g. std::enable_if.
-      for (NamedDecl *P : *Params) {
-        if (!P->getIdentifier())
-          return false;
-      }
+    // Function templates must be defined in the same file.
+    if (MD->getDescribedTemplate())
       SameFile = true;
-    }
 
     // The refactoring is meaningless for unnamed classes and namespaces,
     // unless we're outlining in the same file

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
index d2d2ae9e7bb610..b5f09f9b14604f 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -118,12 +118,6 @@ TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) {
     template <> void fo^o<int>() {}
   )cpp");
 
-  // Not available on member function templates with unnamed template
-  // parameters.
-  EXPECT_UNAVAILABLE(R"cpp(
-    struct Foo { template <typename> void ba^r() {} };
-  )cpp");
-
   // Not available on methods of unnamed classes.
   EXPECT_UNAVAILABLE(R"cpp(
     struct Foo {
@@ -410,14 +404,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>
+              template <typename T, typename, bool B = true>
               T ^bar() { return {}; }
             };)cpp",
           R"cpp(
             struct Foo {
-              template <typename T, bool B = true>
+              template <typename T, typename, bool B = true>
               T bar() ;
-            };template <typename T, bool B>
+            };template <typename T, typename, bool B>
 inline T Foo::bar() { return {}; }
 )cpp",
           ""},
@@ -426,13 +420,13 @@ inline T Foo::bar() { return {}; }
       {
           R"cpp(
             template <typename T> struct Foo {
-              template <typename U> T ^bar(const T& t, const U& u) { return {}; }
+              template <typename U, bool> T ^bar(const T& t, const U& u) { return {}; }
             };)cpp",
           R"cpp(
             template <typename T> struct Foo {
-              template <typename U> T bar(const T& t, const U& u) ;
+              template <typename U, bool> T bar(const T& t, const U& u) ;
             };template <typename T>
-template <typename U>
+template <typename U, bool>
 inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
 )cpp",
           ""},


        


More information about the cfe-commits mailing list