-
Notifications
You must be signed in to change notification settings - Fork 375
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
Conversation
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 Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
a016b81
to
1b635a4
Compare
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
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 |
There was a problem hiding this comment.
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/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
This function would allow callers to assign to the contained
Status
and potentially violate class invariants. For example:
This PR fixes the above API bug by removing the
status()
accessor thatreturns the lvalue to non-const T.
I also remove the
status()
overload that returns the rvalue-ref toconst-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 thatabsl::StatusOr
1 has, so we match there.This change is