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,24 @@ class SynthesizingCodeRAII {
430430 SynthesizingCodeRAII (Interpreter* i) : m_Interpreter(i) {}
431431 // ~SynthesizingCodeRAII() {} // TODO: implement
432432};
433+
434+ class DiagnosticsEngineRAII {
435+ private:
436+ clang::DiagnosticsEngine& diags;
437+
438+ public:
439+ bool reset_condition; // additional condition to reset diagnostics
440+
441+ DiagnosticsEngineRAII (clang::DiagnosticsEngine& d, bool c = true ) : diags(d), reset_condition(c) {}
442+ ~DiagnosticsEngineRAII () {
443+ if (diags.hasErrorOccurred () && reset_condition) {
444+ // instantiation failed, need to reset DiagnosticsEngine
445+ diags.Reset (/* soft=*/ true );
446+ diags.getClient ()->clear ();
447+ }
448+ }
449+ };
450+
433451} // namespace compat
434452
435453#endif // CPPINTEROP_USE_REPL
Original file line number Diff line number Diff line change @@ -312,13 +312,7 @@ 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 (), !FD->isDefined ());
322316 }
323317}
324318
You can’t perform that action at this time.
0 commit comments