diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -265,6 +265,13 @@ /// Allow a diagnostic to be converted to 'failure'. operator LogicalResult() const; + /// Allow a diagnostic to be converted to FailureOr. Always results in + /// 'failure' because this cast cannot possibly return an object of 'T'. + template + operator FailureOr() const { + return failure(); + } + private: Diagnostic(const Diagnostic &rhs) = delete; Diagnostic &operator=(const Diagnostic &rhs) = delete; @@ -347,6 +354,14 @@ /// 'success' if this is an empty diagnostic. operator LogicalResult() const; + /// Allow an inflight diagnostic to be converted to FailureOr. Always + /// results in 'failure' because this cast cannot possibly return an object of + /// 'T'. + template + operator FailureOr() const { + return failure(); + } + private: InFlightDiagnostic &operator=(const InFlightDiagnostic &) = delete; InFlightDiagnostic &operator=(InFlightDiagnostic &&) = delete;