igor-anferov opened a new issue, #44464:
URL: https://github.com/apache/arrow/issues/44464
### Describe the enhancement requested
In current implementation, arrow::Result::status() always returns internal
status field by const lvalue reference, regardless of Result value category,
which can lead to a lot of bugs. For example, consider the following code:
```c++
if (auto&& status = functionReturningArrowResult().status(); status.ok())
return 0;
return -1;
```
Here call `status.ok()` leads to undefined behavior cause `status` is a
dangling const lvalue reference pointing to the object returned by
`functionReturningArrowResult()` and destructed after `;`.
If arrow::Result had two overloads of status() method for different ref
qualifiers:
```c++
…
class Result {
…
auto status() & -> const Status&{ return status_; }
auto status() && -> Status { return std::move(status_); }
…
};
```
It would prevent such type of bugs, and would allow for better optimized
code (as you could move Status from expiring Result object).
### Component(s)
C++
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]