From 6ba3c94b87a97b8c78c69af744f80ee1f2475812 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 25 Dec 2024 14:30:51 +0800 Subject: [PATCH] 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 Signed-off-by: Gang Wu (cherry picked from commit a2f19888e30b931f494c1ec66a3082c24d441d9a) --- cpp/src/arrow/status.cc | 10 ++++++++++ cpp/src/arrow/status.h | 10 ++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cpp/src/arrow/status.cc b/cpp/src/arrow/status.cc index 368e03cac0b..cf3b48b2ee0 100644 --- a/cpp/src/arrow/status.cc +++ b/cpp/src/arrow/status.cc @@ -138,6 +138,16 @@ std::string Status::ToStringWithoutContextLines() const { return message; } +const std::string& Status::message() const { + static const std::string no_message = ""; + return ok() ? no_message : state_->msg; +} + +const std::shared_ptr& Status::detail() const { + static std::shared_ptr no_detail = NULLPTR; + return state_ ? state_->detail : no_detail; +} + void Status::Abort() const { Abort(std::string()); } void Status::Abort(const std::string& message) const { diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h index ac384fc389a..c6269264cac 100644 --- a/cpp/src/arrow/status.h +++ b/cpp/src/arrow/status.h @@ -329,16 +329,10 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparablecode; } /// \brief Return the specific error message attached to this status. - const std::string& message() const { - static const std::string no_message = ""; - return ok() ? no_message : state_->msg; - } + const std::string& message() const; /// \brief Return the status detail attached to this message. - const std::shared_ptr& detail() const { - static std::shared_ptr no_detail = NULLPTR; - return state_ ? state_->detail : no_detail; - } + const std::shared_ptr& detail() const; /// \brief Return a new Status copying the existing status, but /// updating with the existing detail.