@@ -1289,31 +1289,17 @@ using namespace clang;
12891289
12901290class ASTImporter ::FunctionReturnTypeDeclCycleDetector {
12911291public:
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 ([this , LambdaD]() {
1299+ if (LambdaD) {
1300+ FunctionReturnTypeDeclCycles.erase (LambdaD);
1301+ }
1302+ });
13171303 }
13181304
13191305 bool isCycle (const FunctionDecl *D) const {
@@ -4099,7 +4085,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
40994085
41004086 Error Err = Error::success ();
41014087 auto ScopedReturnTypeDeclCycleDetector =
4102- Importer.FunctionReturnTypeCycleDetector ->detectImportCycle (D);
4088+ Importer.FunctionReturnTypeCycleDetector ->makeScopedCycleDetection (D);
41034089 auto T = importChecked (Err, FromTy);
41044090 auto TInfo = importChecked (Err, FromTSI);
41054091 auto ToInnerLocStart = importChecked (Err, D->getInnerLocStart ());
0 commit comments