From: bzcheeseman <12992886+bzcheeseman@users.noreply.github.com> Date: Wed, 30 Mar 2022 08:36:41 +0000 (-0700) Subject: [mlir] Allow Diagnostic/InFlightDiagnostic to convert to FailureOr. X-Git-Tag: upstream/15.0.7~11978 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4fec44b0e63d0dcde0897cf55670ccc1748c8654;p=platform%2Fupstream%2Fllvm.git [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 --- 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;