Skip to content

Commit

Permalink
Remove const, improve test a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Nov 14, 2024
1 parent 1be8452 commit d552fa5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void Status::AddContextLine(const char* filename, int line, const char* expr) {
// We can't add context lines to a StatusConstant's state, so copy it now
state_ = new State{code(), /*is_constant=*/false, message(), detail()};
}
const_cast<State*>(state_)->msg += ss.str();
state_->msg += ss.str();
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
};
// OK status has a `NULL` state_. Otherwise, `state_` points to
// a `State` structure containing the error code and message(s)
const State* state_;
State* state_;

void DeleteState() noexcept {
// ARROW-2400: On certain compilers, splitting off the slow path improves
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/status_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StatusConstant {
<< "StatusConstant is not intended for use with OK status codes";
}

operator Status() const { // NOLINT(runtime/explicit)
operator Status() { // NOLINT(runtime/explicit)
Status st;
st.state_ = &state_;
return st;
Expand Down
9 changes: 9 additions & 0 deletions cpp/src/arrow/status_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ TEST(StatusTest, StatusConstant) {

Status copy = st;
ASSERT_EQ(&st.message(), &copy.message());
Status moved = std::move(st);
ASSERT_EQ(&copy.message(), &moved.message());
ASSERT_OK(st);

Status other = constant;
ASSERT_EQ(other.code(), StatusCode::Invalid);
ASSERT_EQ(other.message(), "default error");
ASSERT_EQ(other.detail(), nullptr);
ASSERT_EQ(&other.message(), &moved.message());
}

TEST(StatusTest, AndStatus) {
Expand Down

0 comments on commit d552fa5

Please sign in to comment.