Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-45099: [C++] Avoid static const variable in the status.h #45100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wgtmac
Copy link
Member

@wgtmac wgtmac commented Dec 23, 2024

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.

Copy link

⚠️ GitHub issue #45099 has been automatically assigned in GitHub to PR creator.

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do the same thing for this too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this is fine because it is nullptr. But it doesn't hurt to fix it as well.

@github-actions github-actions bot added awaiting review Awaiting review awaiting merge Awaiting merge and removed awaiting review Awaiting review labels Dec 23, 2024
@github-actions github-actions bot added awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting merge Awaiting merge labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants