summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/flag.h10
-rw-r--r--absl/flags/internal/flag.h8
2 files changed, 11 insertions, 7 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index bb917654..4cc8ae37 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -333,8 +333,9 @@ ABSL_NAMESPACE_END
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
absl::flags_internal::HelpArg<AbslFlagHelpGenFor##name>(0), \
&AbslFlagsInitFlag##name}; \
- extern bool FLAGS_no##name; \
- bool FLAGS_no##name = ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
+ extern absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name; \
+ absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name = \
+ ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
#else
// MSVC version uses aggregate initialization. We also do not try to
// optimize away help wrapper.
@@ -345,8 +346,9 @@ ABSL_NAMESPACE_END
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name{ \
ABSL_FLAG_IMPL_FLAGNAME(#name), ABSL_FLAG_IMPL_FILENAME(), \
&AbslFlagHelpGenFor##name::NonConst, &AbslFlagsInitFlag##name}; \
- extern bool FLAGS_no##name; \
- bool FLAGS_no##name = ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
+ extern absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name; \
+ absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name = \
+ ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
#endif
// ABSL_RETIRED_FLAG
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index c1bf8652..ae42dedc 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -648,6 +648,7 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
// This class facilitates Flag object registration and tail expression-based
// flag definition, for example:
// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher);
+struct FlagRegistrarEmpty {};
template <typename T, bool do_register>
class FlagRegistrar {
public:
@@ -660,9 +661,10 @@ class FlagRegistrar {
return *this;
}
- // Make the registrar "die" gracefully as a bool on a line where registration
- // happens. Registrar objects are intended to live only as temporary.
- operator bool() const { return true; } // NOLINT
+ // Make the registrar "die" gracefully as an empty struct on a line where
+ // registration happens. Registrar objects are intended to live only as
+ // temporary.
+ operator FlagRegistrarEmpty() const { return {}; } // NOLINT
private:
Flag<T>* flag_; // Flag being registered (not owned).