From 740b1b6a92ddc938d7e40ec76861865f0d48ad6e Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 16 Nov 2023 15:02:23 -0800 Subject: [PATCH] Actually make `status_or.h` compatible with `.clang-tidy`. --- fml/status_or.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fml/status_or.h b/fml/status_or.h index 537878fff6f3b..336d1e0f3664b 100644 --- a/fml/status_or.h +++ b/fml/status_or.h @@ -37,7 +37,10 @@ class StatusOr { // These constructors are intended be compatible with absl::status_or. // NOLINTNEXTLINE(google-explicit-constructor) - StatusOr(const Status& status) : status_(status), value_() {} + StatusOr(const Status& status) : status_(status), value_() { + // It's not valid to construct a StatusOr with an OK status and no value. + FML_CHECK(!status_.ok()); + } StatusOr(const StatusOr&) = default; StatusOr(StatusOr&&) = default; @@ -68,7 +71,8 @@ class StatusOr { bool ok() const { return status_.ok(); } const T& value() const { - if (status_.ok()) { + if (value_.has_value()) { + FML_DCHECK(status_.ok()); return value_.value(); } FML_LOG(FATAL) << "StatusOr::value() called on error Status"; @@ -76,7 +80,8 @@ class StatusOr { } T& value() { - if (status_.ok()) { + if (value_.has_value()) { + FML_DCHECK(status_.ok()); return value_.value(); } FML_LOG(FATAL) << "StatusOr::value() called on error Status";