From 4fec44b0e63d0dcde0897cf55670ccc1748c8654 Mon Sep 17 00:00:00 2001 From: bzcheeseman <12992886+bzcheeseman@users.noreply.github.com> Date: Wed, 30 Mar 2022 01:36:41 -0700 Subject: [PATCH] [mlir] Allow Diagnostic/InFlightDiagnostic to convert to FailureOr. Allow conversion of a diagnostic to FailureOr. This conversion only results in `failure` because in the case where operator LogicalResult would return success, the FailureOr constructor would assert. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D122596 --- mlir/include/mlir/IR/Diagnostics.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h index 97f333a..600a6f9 100644 --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -265,6 +265,13 @@ public: /// 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 @@ public: /// '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; -- 2.7.4