summaryrefslogtreecommitdiff
path: root/absl/status
diff options
context:
space:
mode:
Diffstat (limited to 'absl/status')
-rw-r--r--absl/status/BUILD.bazel1
-rw-r--r--absl/status/CMakeLists.txt1
-rw-r--r--absl/status/status.cc12
3 files changed, 7 insertions, 7 deletions
diff --git a/absl/status/BUILD.bazel b/absl/status/BUILD.bazel
index 10f05f66..3cf0a5e1 100644
--- a/absl/status/BUILD.bazel
+++ b/absl/status/BUILD.bazel
@@ -53,6 +53,7 @@ cc_library(
"//absl/base:atomic_hook",
"//absl/base:config",
"//absl/base:core_headers",
+ "//absl/base:no_destructor",
"//absl/base:raw_logging_internal",
"//absl/base:strerror",
"//absl/container:inlined_vector",
diff --git a/absl/status/CMakeLists.txt b/absl/status/CMakeLists.txt
index fc4ae507..da789901 100644
--- a/absl/status/CMakeLists.txt
+++ b/absl/status/CMakeLists.txt
@@ -36,6 +36,7 @@ absl_cc_library(
absl::function_ref
absl::inlined_vector
absl::memory
+ absl::no_destructor
absl::optional
absl::raw_logging_internal
absl::span
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)