[refactor][extract] avoid extracting expressions from types in functions
llvm-svn: 318169
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
index ab2be15..4f1168b 100644
--- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp
+++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
@@ -383,10 +383,12 @@
if (const auto *D = Node.get<Decl>()) {
if (isFunctionLikeDeclaration(D))
return IsPrevCompound;
- // FIXME (Alex L): We should return false on top-level decls in functions
- // e.g. we don't want to extract:
+ // Stop the search at any type declaration to avoid returning true for
+ // expressions in type declarations in functions, like:
// function foo() { struct X {
// int m = /*selection:*/ 1 + 2 /*selection end*/; }; };
+ if (isa<TypeDecl>(D))
+ return false;
}
IsPrevCompound = Node.get<CompoundStmt>() != nullptr;
}