Skip to content

Commit

Permalink
[clangd] Drop explicit specifier on define out-of-line
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kadircet committed Mar 11, 2021
1 parent 77394c1 commit b1a5df1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit b1a5df1

Please sign in to comment.