Skip to content

Commit

Permalink
Make fml/status_or.h compatible with .clang_tidy. (#48002)
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey authored Nov 16, 2023
1 parent 27fe2c3 commit f8698f8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions fml/status_or.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ namespace fml {
template <typename T>
class StatusOr {
public:
// These constructors are intended be compatible with absl::status_or.
// NOLINTNEXTLINE(google-explicit-constructor)
StatusOr(const T& value) : status_(), value_(value) {}

// These constructors are intended be compatible with absl::status_or.
// NOLINTNEXTLINE(google-explicit-constructor)
StatusOr(const Status& status) : status_(status), value_() {}

StatusOr(const StatusOr&) = default;
Expand Down Expand Up @@ -63,13 +68,19 @@ class StatusOr {
bool ok() const { return status_.ok(); }

const T& value() const {
FML_CHECK(status_.ok());
return value_.value();
if (status_.ok()) {
return value_.value();
}
FML_LOG(FATAL) << "StatusOr::value() called on error Status";
FML_UNREACHABLE();
}

T& value() {
FML_CHECK(status_.ok());
return value_.value();
if (status_.ok()) {
return value_.value();
}
FML_LOG(FATAL) << "StatusOr::value() called on error Status";
FML_UNREACHABLE();
}

private:
Expand Down

0 comments on commit f8698f8

Please sign in to comment.