diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel index f51fdf7558a..170d1ba82d0 100644 --- a/absl/flags/BUILD.bazel +++ b/absl/flags/BUILD.bazel @@ -190,6 +190,7 @@ cc_library( ":private_handle_accessor", "//absl/base:config", "//absl/base:core_headers", + "//absl/base:no_destructor", "//absl/container:flat_hash_map", "//absl/strings", "//absl/synchronization", diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt index a535b55e843..ddf2d4e765f 100644 --- a/absl/flags/CMakeLists.txt +++ b/absl/flags/CMakeLists.txt @@ -169,6 +169,7 @@ absl_cc_library( absl::strings absl::synchronization absl::flat_hash_map + absl::no_destructor ) # Internal-only target, do not depend on directly. diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc index dbce4032ab6..841921a926f 100644 --- a/absl/flags/reflection.cc +++ b/absl/flags/reflection.cc @@ -21,6 +21,7 @@ #include #include "absl/base/config.h" +#include "absl/base/no_destructor.h" #include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" #include "absl/flags/commandlineflag.h" @@ -169,7 +170,7 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag, const char* filename) { } FlagRegistry& FlagRegistry::GlobalRegistry() { - static FlagRegistry* global_registry = new FlagRegistry; + static absl::NoDestructor global_registry; return *global_registry; }