From 6f19a763ec4f0a8c9f4fa103e88c5bf3ed3b4a26 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Fri, 17 Nov 2023 09:07:05 -0800 Subject: [PATCH] Actually make `status_or.h` compatible with `.clang-tidy`. (flutter/engine#48151) I needed to actually convince the checker I wasn't causing a value read on a non-value. I think this is right? --- engine/src/flutter/fml/status_or.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/fml/status_or.h b/engine/src/flutter/fml/status_or.h index 537878fff6..336d1e0f36 100644 --- a/engine/src/flutter/fml/status_or.h +++ b/engine/src/flutter/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";