File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -430,6 +430,7 @@ class SynthesizingCodeRAII {
430430 SynthesizingCodeRAII (Interpreter* i) : m_Interpreter(i) {}
431431 // ~SynthesizingCodeRAII() {} // TODO: implement
432432};
433+
433434} // namespace compat
434435
435436#endif // CPPINTEROP_USE_REPL
@@ -466,6 +467,25 @@ inline void InstantiateClassTemplateSpecialization(
466467 /* PrimaryHasMatchedPackOnParmToNonPackOnArg=*/ false );
467468#endif
468469}
470+
471+ class DiagnosticsEngineRAII {
472+ private:
473+ clang::DiagnosticsEngine& diags;
474+
475+ public:
476+ bool reset_condition; // additional condition to reset diagnostics
477+
478+ DiagnosticsEngineRAII (clang::DiagnosticsEngine& d, bool c = true )
479+ : diags(d), reset_condition(c) {}
480+ ~DiagnosticsEngineRAII () {
481+ if (diags.hasErrorOccurred () && reset_condition) {
482+ // instantiation failed, need to reset DiagnosticsEngine
483+ diags.Reset (/* soft=*/ true );
484+ diags.getClient ()->clear ();
485+ }
486+ }
487+ };
488+
469489} // namespace compat
470490
471491#endif // CPPINTEROP_COMPATIBILITY_H
Original file line number Diff line number Diff line change @@ -312,13 +312,8 @@ static void InstantiateFunctionDefinition(Decl* D) {
312312 getSema ().InstantiateFunctionDefinition (SourceLocation (), FD,
313313 /* Recursive=*/ true ,
314314 /* DefinitionRequired=*/ true );
315- // FIXME: this can go into a RAII object
316- clang::DiagnosticsEngine& Diags = getSema ().getDiagnostics ();
317- if (!FD->isDefined () && Diags.hasErrorOccurred ()) {
318- // instantiation failed, need to reset DiagnosticsEngine
319- Diags.Reset (/* soft=*/ true );
320- Diags.getClient ()->clear ();
321- }
315+ compat::DiagnosticsEngineRAII diagsRAII (getSema ().getDiagnostics (),
316+ !FD->isDefined ());
322317 }
323318}
324319
You can’t perform that action at this time.
0 commit comments