[PATCH] D147802: [clangd] Handle destructors in DefineOutline tweak

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 7 13:01:24 PDT 2023


njames93 updated this revision to Diff 511780.
njames93 added a comment.

Clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147802/new/

https://reviews.llvm.org/D147802

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


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -319,6 +319,12 @@
             };)cpp",
           "  Foo::Foo(int) {}\n",
       },
+      // Destrctors
+      {
+          "class A { ~A^(){} };",
+          "class A { ~A(); };",
+          "A::~A(){} ",
+      },
   };
   for (const auto &Case : Cases) {
     SCOPED_TRACE(Case.Test);
@@ -532,6 +538,18 @@
           // account. This can be spelled as b::foo instead.
           "using namespace a;void a::b::foo() {} ",
       },
+      {
+          "namespace a { class A { ~A^(){} }; }",
+          "",
+          "namespace a { class A { ~A(); }; }",
+          "a::A::~A(){} ",
+      },
+      {
+          "namespace a { class A { ~A^(){} }; }",
+          "namespace a{}",
+          "namespace a { class A { ~A(); }; }",
+          "namespace a{A::~A(){} }",
+      },
   };
   llvm::StringMap<std::string> EditedFiles;
   for (auto &Case : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -183,6 +183,15 @@
       },
       Resolver);
 
+  if (const auto *Destructor = llvm::dyn_cast<CXXDestructorDecl>(FD)) {
+    if (auto Err = DeclarationCleanups.add(tooling::Replacement(
+            SM, Destructor->getLocation(), 0,
+            getQualification(AST, *TargetContext,
+                             SM.getLocForStartOfFile(SM.getMainFileID()),
+                             Destructor))))
+      Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+  }
+
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147802.511780.patch
Type: text/x-patch
Size: 2039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230407/1a93ef53/attachment-0001.bin>


More information about the cfe-commits mailing list