[PATCH] D147808: [clangd] Support non-trivial defaulted special member functions in Define Outline tweak
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 4 07:58:58 PDT 2023
njames93 updated this revision to Diff 519496.
njames93 added a comment.
Fix clang-format issues. Ping?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147808/new/
https://reviews.llvm.org/D147808
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
@@ -110,6 +110,16 @@
};
} // namespace
)cpp");
+
+ // Not available on trivially defaulted functions
+ EXPECT_UNAVAILABLE(R"cpp(
+ struct A {
+ A^() = default;
+ };)cpp");
+ EXPECT_UNAVAILABLE(R"cpp(
+ struct A {
+ ~A^() = default;
+ };)cpp");
}
TEST_F(DefineOutlineTest, FailsWithoutSource) {
@@ -325,6 +335,37 @@
"class A { ~A(); };",
"A::~A(){} ",
},
+ // Defaulted Functions
+ {
+ R"cpp(
+ struct A { A (); };
+ struct B {
+ A a;
+ B^() = default;
+ };)cpp",
+ R"cpp(
+ struct A { A (); };
+ struct B {
+ A a;
+ B() ;
+ };)cpp",
+ "B::B() = default;",
+ },
+ {
+ R"cpp(
+ struct A { ~A (); };
+ struct B {
+ A a;
+ ~B^() = default;
+ };)cpp",
+ R"cpp(
+ struct A { ~A (); };
+ struct B {
+ A a;
+ ~B() ;
+ };)cpp",
+ "B::~B() = default;",
+ },
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Test);
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
@@ -325,6 +325,14 @@
// initializers.
SourceRange getDeletionRange(const FunctionDecl *FD,
const syntax::TokenBuffer &TokBuf) {
+ if (FD->isExplicitlyDefaulted()) {
+ auto Toks =
+ TokBuf.expandedTokens({FD->getTypeSpecEndLoc(), FD->getDefaultLoc()});
+ Toks = Toks.drop_until(
+ [](const syntax::Token &Tok) { return Tok.kind() == tok::equal; });
+ assert(Toks.size() == 2);
+ return {Toks.front().location(), Toks.back().endLocation()};
+ }
auto DeletionRange = FD->getBody()->getSourceRange();
if (auto *CD = llvm::dyn_cast<CXXConstructorDecl>(FD)) {
// AST doesn't contain the location for ":" in ctor initializers. Therefore
@@ -395,7 +403,10 @@
Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
// Bail out if the selection is not a in-line function definition.
- if (!Source || !Source->doesThisDeclarationHaveABody() ||
+ // unless its a not-trivial special member function
+ if (!Source ||
+ (!Source->doesThisDeclarationHaveABody() &&
+ (!Source->isExplicitlyDefaulted() || Source->isTrivial())) ||
Source->isOutOfLine())
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147808.519496.patch
Type: text/x-patch
Size: 2940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230504/c7cc0786/attachment.bin>
More information about the cfe-commits
mailing list