Skip to content

Commit e12db08

Browse files
Use llvm::make_scope_exit
1 parent 3d47bec commit e12db08

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,31 +1289,18 @@ using namespace clang;
12891289

12901290
class ASTImporter::FunctionReturnTypeDeclCycleDetector {
12911291
public:
1292-
class DeclCycleMapInserter {
1293-
public:
1294-
// Do not track cycles on D == nullptr.
1295-
DeclCycleMapInserter(FunctionReturnTypeDeclCycleDetector &owner,
1296-
const FunctionDecl *D)
1297-
: CycleDetector(owner), D(D) {
1298-
if (D)
1299-
CycleDetector.FunctionReturnTypeDeclCycles.insert(D);
1300-
}
1301-
~DeclCycleMapInserter() {
1302-
if (D)
1303-
CycleDetector.FunctionReturnTypeDeclCycles.erase(D);
1292+
auto makeScopedCycleDetection(const FunctionDecl *D) {
1293+
const FunctionDecl *LambdaD = nullptr;
1294+
if (!isCycle(D) && D) {
1295+
FunctionReturnTypeDeclCycles.insert(D);
1296+
LambdaD = D;
13041297
}
1305-
DeclCycleMapInserter(const DeclCycleMapInserter &) = delete;
1306-
DeclCycleMapInserter &operator=(const DeclCycleMapInserter &) = delete;
1307-
1308-
private:
1309-
FunctionReturnTypeDeclCycleDetector &CycleDetector;
1310-
const FunctionDecl *D;
1311-
};
1312-
1313-
DeclCycleMapInserter detectImportCycle(const FunctionDecl *D) {
1314-
if (!isCycle(D))
1315-
return DeclCycleMapInserter(*this, D);
1316-
return DeclCycleMapInserter(*this, nullptr);
1298+
return llvm::make_scope_exit(
1299+
[this, LambdaD]() {
1300+
if (LambdaD) {
1301+
FunctionReturnTypeDeclCycles.erase(LambdaD);
1302+
}
1303+
});
13171304
}
13181305

13191306
bool isCycle(const FunctionDecl *D) const {
@@ -4099,7 +4086,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
40994086

41004087
Error Err = Error::success();
41014088
auto ScopedReturnTypeDeclCycleDetector =
4102-
Importer.FunctionReturnTypeCycleDetector->detectImportCycle(D);
4089+
Importer.FunctionReturnTypeCycleDetector->makeScopedCycleDetection(D);
41034090
auto T = importChecked(Err, FromTy);
41044091
auto TInfo = importChecked(Err, FromTSI);
41054092
auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());

0 commit comments

Comments
 (0)