diff options
Diffstat (limited to 'clang/lib/Tooling/Refactoring/ASTSelection.cpp')
-rw-r--r-- | clang/lib/Tooling/Refactoring/ASTSelection.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp index ab2be155121..4f1168becf8 100644 --- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp +++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp @@ -383,10 +383,12 @@ bool CodeRangeASTSelection::isInFunctionLikeBodyOfCode() const { 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; } |