[clangd] Drop explicit specifier on define out-of-line
authorKadir Cetinkaya <kadircet@google.com>
Mon, 8 Mar 2021 08:00:48 +0000 (09:00 +0100)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 11 Mar 2021 12:27:24 +0000 (13:27 +0100)
Explicit specifier can only be mentioned on the in-line declaration of a
constructor, so don't carry it over to the definition.

Differential Revision: https://reviews.llvm.org/D98164

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

index 4cdd36c..18c5211 100644 (file)
@@ -272,6 +272,10 @@ getFunctionSourceCode(const FunctionDecl *FD, llvm::StringRef TargetNamespace,
     if (MD->isStatic())
       DelKeyword(tok::kw_static, {FD->getBeginLoc(), FD->getLocation()});
   }
+  if (const auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
+    if (CD->isExplicit())
+      DelKeyword(tok::kw_explicit, {FD->getBeginLoc(), FD->getLocation()});
+  }
 
   if (Errors)
     return std::move(Errors);
index fa62728..a872341 100644 (file)
@@ -267,6 +267,28 @@ TEST_F(DefineOutlineTest, ApplyTest) {
             };)cpp",
           "  void A::foo() {}\n",
       },
+      {
+          R"cpp(
+            struct Foo {
+              explicit Fo^o(int) {}
+            };)cpp",
+          R"cpp(
+            struct Foo {
+              explicit Foo(int) ;
+            };)cpp",
+          " Foo::Foo(int) {}\n",
+      },
+      {
+          R"cpp(
+            struct Foo {
+              explicit explicit Fo^o(int) {}
+            };)cpp",
+          R"cpp(
+            struct Foo {
+              explicit explicit Foo(int) ;
+            };)cpp",
+          "  Foo::Foo(int) {}\n",
+      },
   };
   for (const auto &Case : Cases) {
     SCOPED_TRACE(Case.Test);