mutable DiagnosticsEngine *DiagObj;
mutable unsigned NumArgs, NumRanges, NumFixits;
+ /// \brief Status variable indicating if this diagnostic is still active.
+ ///
+ // NOTE: This field is redundant with DiagObj (IsActive iff (DiagObj == 0)),
+ // but LLVM is not currently smart enough to eliminate the null check that
+ // Emit() would end up with if we used that as our status variable.
+ mutable bool IsActive;
+
void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
friend class DiagnosticsEngine;
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
- : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0) {
+ : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(true) {
assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!");
}
}
/// \brief Clear out the current diagnostic.
- void Clear() { DiagObj = 0; }
+ void Clear() const {
+ DiagObj = 0;
+ IsActive = false;
+ }
/// isActive - Determine whether this diagnostic is still active.
- bool isActive() const { return DiagObj != 0; }
+ bool isActive() const { return IsActive; }
/// \brief Force the diagnostic builder to emit the diagnostic now.
///
/// \returns true if a diagnostic was emitted, false if the
/// diagnostic was suppressed.
bool Emit() {
- // If DiagObj is null, then its soul was stolen by the copy ctor
- // or the user called Emit().
- if (DiagObj == 0) return false;
+ // If this diagnostic is inactive, then its soul was stolen by the copy ctor
+ // (or by a subclass, as in SemaDiagnosticBuilder).
+ if (!isActive()) return false;
// When emitting diagnostics, we set the final argument count into
// the DiagnosticsEngine object.
bool Result = DiagObj->EmitCurrentDiagnostic();
// This diagnostic is dead.
- DiagObj = 0;
+ Clear();
return Result;
}
/// input and neuters it.
DiagnosticBuilder(const DiagnosticBuilder &D) {
DiagObj = D.DiagObj;
- D.DiagObj = 0;
+ IsActive = D.IsActive;
+ D.Clear();
NumArgs = D.NumArgs;
NumRanges = D.NumRanges;
NumFixits = D.NumFixits;