Skip to content

Commit 7ac10e5

Browse files
committed
[clangd] Fix a crash in ExtractFunction tweak.
Differential Revision: https://reviews.llvm.org/D135857
1 parent 3be72f4 commit 7ac10e5

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ const FunctionDecl *findEnclosingFunction(const Node *CommonAnc) {
248248
// FIXME: Support extraction from templated functions.
249249
if (Func->isTemplated())
250250
return nullptr;
251+
if (!Func->getBody())
252+
return nullptr;
251253
for (const auto *S : Func->getBody()->children()) {
252254
// During apply phase, we perform semantic analysis (e.g. figure out
253255
// what variables requires hoisting). We cannot perform those when the

clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ F (extracted();)
182182

183183
// Shouldn't crash.
184184
EXPECT_EQ(apply("void f([[int a]]);"), "unavailable");
185+
EXPECT_EQ(apply("void f(int a = [[1]]);"), "unavailable");
185186
// Don't extract if we select the entire function body (CompoundStmt).
186187
std::string CompoundFailInput = R"cpp(
187188
void f() [[{

0 commit comments

Comments
 (0)