This is an automated email from the ASF dual-hosted git repository.

gangwu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new a2f19888e3 GH-45099: [C++] Avoid static const variable in the status.h 
(#45100)
a2f19888e3 is described below

commit a2f19888e30b931f494c1ec66a3082c24d441d9a
Author: Gang Wu <[email protected]>
AuthorDate: Wed Dec 25 14:30:51 2024 +0800

    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]>
---
 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 8cbc6842c4..55ce3fb78d 100644
--- a/cpp/src/arrow/status.cc
+++ b/cpp/src/arrow/status.cc
@@ -141,6 +141,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<StatusDetail>& Status::detail() const {
+  static std::shared_ptr<StatusDetail> 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 853fc284ee..42e8929ce0 100644
--- a/cpp/src/arrow/status.h
+++ b/cpp/src/arrow/status.h
@@ -332,16 +332,10 @@ class ARROW_EXPORT [[nodiscard]] Status : public 
util::EqualityComparable<Status
   constexpr StatusCode code() const { return ok() ? StatusCode::OK : 
state_->code; }
 
   /// \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<StatusDetail>& detail() const {
-    static std::shared_ptr<StatusDetail> no_detail = NULLPTR;
-    return state_ ? state_->detail : no_detail;
-  }
+  const std::shared_ptr<StatusDetail>& detail() const;
 
   /// \brief Return a new Status copying the existing status, but
   /// updating with the existing detail.

Reply via email to