-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2298 VERIFY_RESULT creates undesirable copy of Result<T&>'s value
Summary: 1. `VERIFY_RESULT` and similar macros uses GNU expression statement `__extension__` ``` #define VERIFY_RESULT(expr) \ __extension__ ({ auto&& __result = (expr); RETURN_NOT_OK(__result); std::move(*__result); }) ``` In spite of the fact last statement is a rvalue reference copy object is created by using of `T(T&&)` move-constructor (if any) for `Result<T>/Result<T&>` situation and `T::T(const T&)` copy-constructor (if any) for `Result<const T&>` To avoid undesirable copying of `T` object in case of `Result<T&>` and `Result<const T&>` `std::reference_wrapper<T>` is returned from expression statement `__extension__`. As of now `VERIFY_RESULT` and similar macros returns `std::reference_wrapper<T>` for `Result<T&>/Result<const T&>` situation new helper macro `VERIFY_RESULT_REF` is introduced (it is still safe to use `VERIFY_RESULT` in this situation). It is useful with `auto`: ``` Result<const vector<int>&> GetVector() { static const vector<int> values{1, 2, 3}; return values; } const auto& value = VERIFY_RESULT_REF(GetVector()); ... for(const auto& i : VERIFY_RESULT_REF(GetVector())) { ... } ``` 2. Make `Status::OK()` be a wrapper to avoid creation of `Result<T>` from it at compile time Test Plan: New unit test was introduced ``` ./yb_build.sh --cxx-test result-test ``` Reviewers: mikhail, sergei Reviewed By: sergei Subscribers: bogdan, ybase Differential Revision: https://phabricator.dev.yugabyte.com/D7204
- Loading branch information
1 parent
2498149
commit 247eb69
Showing
19 changed files
with
138 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.