Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(statusor)!: remove status() accessor returning non-const lvalue #7150

Merged
merged 3 commits into from
Aug 10, 2021

Conversation

devjgm
Copy link
Contributor

@devjgm devjgm commented Aug 10, 2021

This function would allow callers to assign to the contained Status
and potentially violate class invariants. For example:

StatusOr<Foo> sor;  // constructed with kUnknown and no Foo
sor.status() = Status{};  // BUG
auto v = sor.value();  // :-|

This PR fixes the above API bug by removing the status() accessor that
returns the lvalue to non-const T.

I also remove the status() overload that returns the rvalue-ref to
const-T, because I don't think it adds any new functionality to the
class, and a "move" isn't actually happening behind the scenes. Also,
the two access that remain (const & and &&) are the same two that
absl::StatusOr 1 has, so we match there.


This change is Reviewable

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 10, 2021
This function would allow callers to assign to the contained `Status`
and potentially violate class invariants. For example:

```cc
StatusOr<Foo> sor;  // constructed with kUnknown and no Foo
sor.status() = Status{};  // BUG
auto v = sor.value();  // :-|
```

This PR fixes the above API bug by removing the `status()` accessor that
returns the lvalue to non-const T.

I also remove the `status()` overload that returns the rvalue-ref to
const-T, because I don't think it adds any new functionality to the
class, and a "move" isn't actually happening behind the scenes. Also,
the two access that remain (`const &` and `&&`) are the same two that
`absl::StatusOr` [1] has, so we match there.

[1]: https://github.com/abseil/abseil-cpp/blob/bf31a10b65d945665cecfb9d8807702ae4a7fde1/absl/status/statusor.h#L492-L493
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: a016b81330c0b512859322c137a715355612aaf4

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #7150 (e941d59) into main (5d727eb) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7150      +/-   ##
==========================================
- Coverage   94.49%   94.49%   -0.01%     
==========================================
  Files        1310     1310              
  Lines      113220   113212       -8     
==========================================
- Hits       106989   106981       -8     
  Misses       6231     6231              
Impacted Files Coverage Δ
google/cloud/status_or.h 100.00% <ø> (ø)
...igtable/benchmarks/read_sync_vs_async_benchmark.cc 95.62% <100.00%> (ø)
...gle/cloud/spanner/internal/connection_impl_test.cc 97.59% <100.00%> (-0.01%) ⬇️
google/cloud/bigtable/internal/common_client.cc 97.14% <0.00%> (-2.86%) ⬇️
...bigtable/examples/bigtable_hello_instance_admin.cc 81.31% <0.00%> (-2.20%) ⬇️
google/cloud/internal/async_retry_unary_rpc.h 96.15% <0.00%> (-0.15%) ⬇️
google/cloud/bigtable/internal/async_poll_op.h 95.65% <0.00%> (-0.10%) ⬇️
...e/cloud/bigtable/internal/async_retry_multi_page.h 96.66% <0.00%> (-0.06%) ⬇️
.../spanner/benchmarks/multiple_rows_cpu_benchmark.cc 83.71% <0.00%> (+0.10%) ⬆️
...le/cloud/storage/internal/curl_download_request.cc 89.59% <0.00%> (+0.37%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d727eb...e941d59. Read the comment docs.

@devjgm devjgm force-pushed the fix-statusor-accessors branch from a016b81 to 1b635a4 Compare August 10, 2021 17:10
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 1b635a4157aca667fa35e73f0ef3d010f0363793

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: f695cb0020b97ae023ece442541ddc4d0b3d7b56

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@devjgm devjgm marked this pull request as ready for review August 10, 2021 17:54
@devjgm devjgm requested a review from a team as a code owner August 10, 2021 17:54
CHANGELOG.md Outdated
**BREAKING CHANGES**:

* `google::cloud::StatusOr<T>` had an accessor that returned an lvalue
reference to non-const `Status`, which could allow callers to modify the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/, which could allow/. This allowed/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: e941d590f53cc211179d02e0568ba3f887cce605

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@devjgm devjgm merged commit 947b751 into googleapis:main Aug 10, 2021
@devjgm devjgm deleted the fix-statusor-accessors branch August 10, 2021 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants