aboutsummaryrefslogtreecommitdiff
path: root/cc/util
diff options
context:
space:
mode:
authorlizatretyakova <lizatretyakova@google.com>2022-03-18 05:21:51 -0700
committerCopybara-Service <copybara-worker@google.com>2022-03-18 05:22:43 -0700
commit04e1fe8df66013ae842be110a876371fa57388d9 (patch)
tree7c96ead74b19160e26be16335a02b3342c2b86e3 /cc/util
parentf18d2693658ff5071928fd3f8472bbed9aab4972 (diff)
downloadtink-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.h2
-rw-r--r--cc/util/statusor_test.cc10
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);