From e5c6ccbc9623a0c9a1a64ac2662ed0c27b2c0fe9 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 13 Oct 2025 23:47:49 -0700 Subject: [PATCH] FlagStateInterface implementors need only support being restored once. PiperOrigin-RevId: 819030565 Change-Id: I92ac8ce4318f8d2e575c13752e490326030ba583 --- absl/flags/internal/commandlineflag.h | 2 +- absl/flags/internal/flag.cc | 5 +++-- absl/flags/reflection.cc | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h index daef4e35..e2c4c82f 100644 --- a/absl/flags/internal/commandlineflag.h +++ b/absl/flags/internal/commandlineflag.h @@ -58,7 +58,7 @@ class FlagStateInterface { virtual ~FlagStateInterface(); // Restores the flag originated this object to the saved state. - virtual void Restore() const = 0; + virtual void Restore() && = 0; }; } // namespace flags_internal diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc index b05e1bdc..8e894250 100644 --- a/absl/flags/internal/flag.cc +++ b/absl/flags/internal/flag.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "absl/base/attributes.h" @@ -139,8 +140,8 @@ class FlagState : public flags_internal::FlagStateInterface { friend class FlagImpl; // Restores the flag to the saved state. - void Restore() const override { - if (!flag_impl_.RestoreState(*this)) return; + void Restore() && override { + if (!std::move(flag_impl_).RestoreState(*this)) return; ABSL_INTERNAL_LOG(INFO, absl::StrCat("Restore saved value of ", flag_impl_.Name(), diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc index 845099e2..fb64a653 100644 --- a/absl/flags/reflection.cc +++ b/absl/flags/reflection.cc @@ -19,6 +19,7 @@ #include #include +#include #include "absl/base/config.h" #include "absl/base/no_destructor.h" @@ -320,9 +321,9 @@ class FlagSaverImpl { } // Restores the saved flag states into the flag registry. - void RestoreToRegistry() { + void RestoreToRegistry() && { for (const auto& flag_state : backup_registry_) { - flag_state->Restore(); + std::move(*flag_state).Restore(); } } @@ -340,7 +341,7 @@ FlagSaver::FlagSaver() : impl_(new flags_internal::FlagSaverImpl) { FlagSaver::~FlagSaver() { if (!impl_) return; - impl_->RestoreToRegistry(); + std::move(*impl_).RestoreToRegistry(); delete impl_; }