Skip to content

Commit a2f1988

Browse files
authored
GH-45099: [C++] Avoid static const variable in the status.h (#45100)
### Rationale for this change The `Status::message` function below has defined a static const string in the header file which may cause troubles in different translation units. ``` const std::string& message() const { static const std::string no_message = ""; return ok() ? no_message : state_->msg; } ``` ### What changes are included in this PR? Move the definition of `Status::message` function into the source file. ### Are these changes tested? Pass CIs. ### Are there any user-facing changes? No. * GitHub Issue: #45099 Authored-by: Gang Wu <[email protected]> Signed-off-by: Gang Wu <[email protected]>
1 parent e7471f8 commit a2f1988

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cpp/src/arrow/status.cc

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ std::string Status::ToStringWithoutContextLines() const {
141141
return message;
142142
}
143143

144+
const std::string& Status::message() const {
145+
static const std::string no_message = "";
146+
return ok() ? no_message : state_->msg;
147+
}
148+
149+
const std::shared_ptr<StatusDetail>& Status::detail() const {
150+
static std::shared_ptr<StatusDetail> no_detail = NULLPTR;
151+
return state_ ? state_->detail : no_detail;
152+
}
153+
144154
void Status::Abort() const { Abort(std::string()); }
145155

146156
void Status::Abort(const std::string& message) const {

cpp/src/arrow/status.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,10 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
332332
constexpr StatusCode code() const { return ok() ? StatusCode::OK : state_->code; }
333333

334334
/// \brief Return the specific error message attached to this status.
335-
const std::string& message() const {
336-
static const std::string no_message = "";
337-
return ok() ? no_message : state_->msg;
338-
}
335+
const std::string& message() const;
339336

340337
/// \brief Return the status detail attached to this message.
341-
const std::shared_ptr<StatusDetail>& detail() const {
342-
static std::shared_ptr<StatusDetail> no_detail = NULLPTR;
343-
return state_ ? state_->detail : no_detail;
344-
}
338+
const std::shared_ptr<StatusDetail>& detail() const;
345339

346340
/// \brief Return a new Status copying the existing status, but
347341
/// updating with the existing detail.

0 commit comments

Comments
 (0)