diff options
Diffstat (limited to 'absl/flags')
-rw-r--r-- | absl/flags/flag.h | 11 | ||||
-rw-r--r-- | absl/flags/flag_test_defs.cc | 2 | ||||
-rw-r--r-- | absl/flags/internal/registry.h | 17 | ||||
-rw-r--r-- | absl/flags/reflection.cc | 17 |
4 files changed, 23 insertions, 24 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h index 90dc289..e170725 100644 --- a/absl/flags/flag.h +++ b/absl/flags/flag.h @@ -379,11 +379,10 @@ ABSL_NAMESPACE_END // // `default_value` is only used as a double check on the type. `explanation` is // unused. -// TODO(rogeeff): Return an anonymous struct instead of bool, and place it into -// the unnamed namespace. -#define ABSL_RETIRED_FLAG(type, flagname, default_value, explanation) \ - ABSL_ATTRIBUTE_UNUSED static const bool ignored_##flagname = \ - ([] { return type(default_value); }, \ - absl::flags_internal::RetiredFlag<type>(#flagname)) +// TODO(rogeeff): replace RETIRED_FLAGS with FLAGS once forward declarations of +// retired flags are cleaned up. +#define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \ + ABSL_ATTRIBUTE_UNUSED static const absl::flags_internal::RetiredFlag<type> \ + RETIRED_FLAGS_##name(#name) #endif // ABSL_FLAGS_FLAG_H_ diff --git a/absl/flags/flag_test_defs.cc b/absl/flags/flag_test_defs.cc index 49f91de..3366c58 100644 --- a/absl/flags/flag_test_defs.cc +++ b/absl/flags/flag_test_defs.cc @@ -20,5 +20,3 @@ ABSL_FLAG(int, mistyped_int_flag, 0, ""); ABSL_FLAG(std::string, mistyped_string_flag, "", ""); -ABSL_RETIRED_FLAG(bool, old_bool_flag, true, - "repetition of retired flag definition"); diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h index 6f5006a..5f85ded 100644 --- a/absl/flags/internal/registry.h +++ b/absl/flags/internal/registry.h @@ -74,13 +74,22 @@ bool RegisterCommandLineFlag(CommandLineFlag&); // // Retire flag with name "name" and type indicated by ops. -bool Retire(const char* name, FlagFastTypeId type_id); +void Retire(const char* name, FlagFastTypeId type_id, char* buf); + +constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*); +constexpr size_t kRetiredFlagObjAlignment = alignof(void*); // Registered a retired flag with name 'flag_name' and type 'T'. template <typename T> -inline bool RetiredFlag(const char* flag_name) { - return flags_internal::Retire(flag_name, base_internal::FastTypeId<T>()); -} +class RetiredFlag { + public: + explicit RetiredFlag(const char* flag_name) { + flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_); + } + + private: + alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize]; +}; } // namespace flags_internal ABSL_NAMESPACE_END diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc index 1b02583..e4145b3 100644 --- a/absl/flags/reflection.cc +++ b/absl/flags/reflection.cc @@ -99,8 +99,6 @@ class FlagRegistryLock { FlagRegistry& fr_; }; -void DestroyRetiredFlag(CommandLineFlag& flag); - } // namespace void FlagRegistry::RegisterFlag(CommandLineFlag& flag) { @@ -125,8 +123,6 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag) { old_flag.Filename(), "' and '", flag.Filename(), "'."), true); } else if (old_flag.IsRetired()) { - // Retired flag can just be deleted. - DestroyRetiredFlag(flag); return; } else if (old_flag.Filename() != flag.Filename()) { flags_internal::ReportUsageError( @@ -241,17 +237,14 @@ class RetiredFlagObj final : public CommandLineFlag { const FlagFastTypeId type_id_; }; -void DestroyRetiredFlag(CommandLineFlag& flag) { - assert(flag.IsRetired()); - delete static_cast<RetiredFlagObj*>(&flag); -} - } // namespace -bool Retire(const char* name, FlagFastTypeId type_id) { - auto* flag = new flags_internal::RetiredFlagObj(name, type_id); +void Retire(const char* name, FlagFastTypeId type_id, char* buf) { + static_assert(sizeof(RetiredFlagObj) == kRetiredFlagObjSize, ""); + static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, ""); + auto* flag = ::new (static_cast<void*>(buf)) + flags_internal::RetiredFlagObj(name, type_id); FlagRegistry::GlobalRegistry().RegisterFlag(*flag); - return true; } // -------------------------------------------------------------------- |