Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/CppInterOp/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class SynthesizingCodeRAII {
SynthesizingCodeRAII(Interpreter* i) : m_Interpreter(i) {}
// ~SynthesizingCodeRAII() {} // TODO: implement
};

} // namespace compat

#endif // CPPINTEROP_USE_REPL
Expand Down Expand Up @@ -466,6 +467,25 @@ inline void InstantiateClassTemplateSpecialization(
/*PrimaryHasMatchedPackOnParmToNonPackOnArg=*/false);
#endif
}

class DiagnosticsEngineRAII {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: class 'DiagnosticsEngineRAII' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class DiagnosticsEngineRAII {
      ^

private:
clang::DiagnosticsEngine& diags;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'diags' of type 'clang::DiagnosticsEngine &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  clang::DiagnosticsEngine& diags;
                            ^


public:
bool reset_condition; // additional condition to reset diagnostics
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'reset_condition' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  bool reset_condition; // additional condition to reset diagnostics
       ^


DiagnosticsEngineRAII(clang::DiagnosticsEngine& d, bool c = true)
: diags(d), reset_condition(c) {}
~DiagnosticsEngineRAII() {
if (diags.hasErrorOccurred() && reset_condition) {
// instantiation failed, need to reset DiagnosticsEngine
diags.Reset(/*soft=*/true);
diags.getClient()->clear();
}
}
};

} // namespace compat

#endif // CPPINTEROP_COMPATIBILITY_H
9 changes: 2 additions & 7 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,8 @@ static void InstantiateFunctionDefinition(Decl* D) {
getSema().InstantiateFunctionDefinition(SourceLocation(), FD,
/*Recursive=*/true,
/*DefinitionRequired=*/true);
// FIXME: this can go into a RAII object
clang::DiagnosticsEngine& Diags = getSema().getDiagnostics();
if (!FD->isDefined() && Diags.hasErrorOccurred()) {
// instantiation failed, need to reset DiagnosticsEngine
Diags.Reset(/*soft=*/true);
Diags.getClient()->clear();
}
compat::DiagnosticsEngineRAII diagsRAII(getSema().getDiagnostics(),
!FD->isDefined());
}
}

Expand Down
Loading