diff options
author | lizatretyakova <lizatretyakova@google.com> | 2022-03-18 05:21:51 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-03-18 05:22:43 -0700 |
commit | 04e1fe8df66013ae842be110a876371fa57388d9 (patch) | |
tree | 7c96ead74b19160e26be16335a02b3342c2b86e3 /cc/util | |
parent | f18d2693658ff5071928fd3f8472bbed9aab4972 (diff) | |
download | tink-04e1fe8df66013ae842be110a876371fa57388d9.tar.gz |
Make crypto::tink::util::StatusOr::AbortWithMessageFrom const, in order to allow usages of the const versions of value(). Part of the Tink migration towards absl::Status{,Or}.
PiperOrigin-RevId: 435610472
Diffstat (limited to 'cc/util')
-rw-r--r-- | cc/util/statusor.h | 2 | ||||
-rw-r--r-- | cc/util/statusor_test.cc | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/cc/util/statusor.h b/cc/util/statusor.h index 1ed2716c7..b7d9b93c3 100644 --- a/cc/util/statusor.h +++ b/cc/util/statusor.h @@ -169,7 +169,7 @@ class StatusOr { } } - void AbortWithMessageFrom(crypto::tink::util::Status status) { + void AbortWithMessageFrom(crypto::tink::util::Status status) const { std::cerr << "Attempting to fetch value instead of handling error\n"; std::cerr << status.ToString(); std::abort(); diff --git a/cc/util/statusor_test.cc b/cc/util/statusor_test.cc index 5c1ee68c4..993901f7f 100644 --- a/cc/util/statusor_test.cc +++ b/cc/util/statusor_test.cc @@ -132,6 +132,16 @@ TEST(StatusOrTest, MoveOutMoveOnlyValue) { ASSERT_THAT(*ten, Eq(10)); } +TEST(STatusOrTest, CallValueOnConst) { + const StatusOr<int> const_status_or_ten = 10; + ASSERT_THAT(const_status_or_ten.value(), Eq(10)); +} + +TEST(StatusOrTest, CallValueOnConstTemp) { + const StatusOr<int> const_status_or_ten = 10; + ASSERT_THAT(std::move(const_status_or_ten).value(), Eq(10)); +} + TEST(StatusOrTest, TestValueConst) { const int kI = 4; const absl::StatusOr<int> thing(kI); |