arrow
arrow copied to clipboard
[C++] arrow::Result::status() should have rvalue-reference-qualified overload returning value instead of reference
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:
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:
template <…>
class Result {
…
auto status() const & -> 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++