diff options
Diffstat (limited to 'absl/flags')
-rw-r--r-- | absl/flags/flag.h | 8 | ||||
-rw-r--r-- | absl/flags/flag_test.cc | 11 | ||||
-rw-r--r-- | absl/flags/flag_test_defs.cc | 2 | ||||
-rw-r--r-- | absl/flags/internal/registry.h | 2 |
4 files changed, 19 insertions, 4 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h index e1707252..cdac545b 100644 --- a/absl/flags/flag.h +++ b/absl/flags/flag.h @@ -381,8 +381,10 @@ ABSL_NAMESPACE_END // unused. // 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) +#define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \ + static absl::flags_internal::RetiredFlag<type> RETIRED_FLAGS_##name; \ + ABSL_ATTRIBUTE_UNUSED static const auto RETIRED_FLAGS_REG_##name = \ + (RETIRED_FLAGS_##name.Retire(#name), \ + ::absl::flags_internal::FlagRegistrarEmpty{}) #endif // ABSL_FLAGS_FLAG_H_ diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index 2eb2ba71..654c8122 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc @@ -812,6 +812,17 @@ ABSL_RETIRED_FLAG(bool, old_bool_flag, true, "old descr"); ABSL_RETIRED_FLAG(int, old_int_flag, (int)std::sqrt(10), "old descr"); ABSL_RETIRED_FLAG(std::string, old_str_flag, "", absl::StrCat("old ", "descr")); +bool initializaion_order_fiasco_test = [] { + // Iterate over all the flags during static initialization. + // This should not trigger ASan's initialization-order-fiasco. + auto* handle1 = absl::FindCommandLineFlag("flag_on_separate_file"); + auto* handle2 = absl::FindCommandLineFlag("retired_flag_on_separate_file"); + if (handle1 != nullptr && handle2 != nullptr) { + return handle1->Name() == handle2->Name(); + } + return true; +}(); + namespace { TEST_F(FlagTest, TestRetiredFlagRegistration) { diff --git a/absl/flags/flag_test_defs.cc b/absl/flags/flag_test_defs.cc index 3366c580..4e1693cd 100644 --- a/absl/flags/flag_test_defs.cc +++ b/absl/flags/flag_test_defs.cc @@ -20,3 +20,5 @@ ABSL_FLAG(int, mistyped_int_flag, 0, ""); ABSL_FLAG(std::string, mistyped_string_flag, "", ""); +ABSL_FLAG(bool, flag_on_separate_file, false, ""); +ABSL_RETIRED_FLAG(bool, retired_flag_on_separate_file, false, ""); diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h index 5f85ded5..1df2db79 100644 --- a/absl/flags/internal/registry.h +++ b/absl/flags/internal/registry.h @@ -83,7 +83,7 @@ constexpr size_t kRetiredFlagObjAlignment = alignof(void*); template <typename T> class RetiredFlag { public: - explicit RetiredFlag(const char* flag_name) { + void Retire(const char* flag_name) { flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_); } |