Skip to content

Commit f9c5e0c

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e00e70aa45f8' from apple/master into swift/master-next
2 parents 6ae2d65 + e00e70a commit f9c5e0c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

clang/lib/Tooling/Refactor/ImplementDeclaredMethods.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,26 @@ clang::tooling::initiateImplementDeclaredMethodsOperation(
166166
Container, SelectedMethods, CreateOperation);
167167
}
168168

169+
static bool isInLocalScope(const Decl *D) {
170+
const DeclContext *LDC = D->getLexicalDeclContext();
171+
while (true) {
172+
if (LDC->isFunctionOrMethod())
173+
return true;
174+
if (!isa<TagDecl>(LDC))
175+
return false;
176+
if (const auto *CRD = dyn_cast<CXXRecordDecl>(LDC))
177+
if (CRD->isLambda())
178+
return true;
179+
LDC = LDC->getLexicalParent();
180+
}
181+
return false;
182+
}
183+
169184
llvm::Expected<RefactoringResult>
170185
ImplementDeclaredCXXMethodsOperation::perform(
171186
ASTContext &Context, const Preprocessor &ThePreprocessor,
172187
const RefactoringOptionSet &Options, unsigned SelectedCandidateIndex) {
173-
if (Container->isInLocalScopeForInstantiation()) {
188+
if (isInLocalScope(Container)) {
174189
// Local methods can be implemented inline.
175190
std::vector<RefactoringReplacement> Replacements;
176191
for (const CXXMethodDecl *MD : SelectedMethods)

clang/lib/Tooling/Refactor/SymbolOperation.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ static bool escapesEnclosingDecl(const RecordDecl *RD,
8282
escapesEnclosingDecl(RD->getParentFunctionOrMethod(), RD);
8383
}
8484

85+
static bool isInLocalScope(const Decl *D) {
86+
const DeclContext *LDC = D->getLexicalDeclContext();
87+
while (true) {
88+
if (LDC->isFunctionOrMethod())
89+
return true;
90+
if (!isa<TagDecl>(LDC))
91+
return false;
92+
if (const auto *CRD = dyn_cast<CXXRecordDecl>(LDC))
93+
if (CRD->isLambda())
94+
return true;
95+
LDC = LDC->getLexicalParent();
96+
}
97+
return false;
98+
}
99+
85100
/// Return true if the given declaration corresponds to a local symbol.
86101
bool clang::tooling::isLocalSymbol(const NamedDecl *FoundDecl,
87102
const LangOptions &LangOpts) {
@@ -99,7 +114,7 @@ bool clang::tooling::isLocalSymbol(const NamedDecl *FoundDecl,
99114
return false;
100115

101116
// Local declarations are defined in a function or a method, or are anonymous.
102-
if (!FoundDecl->isInLocalScopeForInstantiation())
117+
if (!isInLocalScope(FoundDecl))
103118
return false;
104119

105120
// A locally defined record is global when it is returned from the enclosing

0 commit comments

Comments
 (0)