diff options
Diffstat (limited to 'absl/status/status.cc')
-rw-r--r-- | absl/status/status.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/absl/status/status.cc b/absl/status/status.cc index 7eb5d66a..7c778ac0 100644 --- a/absl/status/status.cc +++ b/absl/status/status.cc @@ -28,6 +28,7 @@ #include "absl/base/internal/raw_logging.h" #include "absl/base/internal/strerror.h" #include "absl/base/macros.h" +#include "absl/base/no_destructor.h" #include "absl/debugging/stacktrace.h" #include "absl/debugging/symbolize.h" #include "absl/status/internal/status_internal.h" @@ -90,11 +91,8 @@ std::ostream& operator<<(std::ostream& os, StatusCode code) { } const std::string* Status::EmptyString() { - static union EmptyString { - std::string str; - ~EmptyString() {} - } empty = {{}}; - return &empty.str; + static const absl::NoDestructor<std::string> kEmpty; + return kEmpty.get(); } #ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL @@ -102,8 +100,8 @@ constexpr const char Status::kMovedFromString[]; #endif const std::string* Status::MovedFromString() { - static std::string* moved_from_string = new std::string(kMovedFromString); - return moved_from_string; + static const absl::NoDestructor<std::string> kMovedFrom(kMovedFromString); + return kMovedFrom.get(); } Status::Status(absl::StatusCode code, absl::string_view msg) |