Skip to content

Commit e5c6ccb

Browse files
sam-mccallcopybara-github
authored andcommitted
FlagStateInterface implementors need only support being restored once.
PiperOrigin-RevId: 819030565 Change-Id: I92ac8ce4318f8d2e575c13752e490326030ba583
1 parent cad6058 commit e5c6ccb

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

absl/flags/internal/commandlineflag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FlagStateInterface {
5858
virtual ~FlagStateInterface();
5959

6060
// Restores the flag originated this object to the saved state.
61-
virtual void Restore() const = 0;
61+
virtual void Restore() && = 0;
6262
};
6363

6464
} // namespace flags_internal

absl/flags/internal/flag.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <memory>
2727
#include <string>
2828
#include <typeinfo>
29+
#include <utility>
2930
#include <vector>
3031

3132
#include "absl/base/attributes.h"
@@ -139,8 +140,8 @@ class FlagState : public flags_internal::FlagStateInterface {
139140
friend class FlagImpl;
140141

141142
// Restores the flag to the saved state.
142-
void Restore() const override {
143-
if (!flag_impl_.RestoreState(*this)) return;
143+
void Restore() && override {
144+
if (!std::move(flag_impl_).RestoreState(*this)) return;
144145

145146
ABSL_INTERNAL_LOG(INFO,
146147
absl::StrCat("Restore saved value of ", flag_impl_.Name(),

absl/flags/reflection.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <atomic>
2121
#include <string>
22+
#include <utility>
2223

2324
#include "absl/base/config.h"
2425
#include "absl/base/no_destructor.h"
@@ -320,9 +321,9 @@ class FlagSaverImpl {
320321
}
321322

322323
// Restores the saved flag states into the flag registry.
323-
void RestoreToRegistry() {
324+
void RestoreToRegistry() && {
324325
for (const auto& flag_state : backup_registry_) {
325-
flag_state->Restore();
326+
std::move(*flag_state).Restore();
326327
}
327328
}
328329

@@ -340,7 +341,7 @@ FlagSaver::FlagSaver() : impl_(new flags_internal::FlagSaverImpl) {
340341
FlagSaver::~FlagSaver() {
341342
if (!impl_) return;
342343

343-
impl_->RestoreToRegistry();
344+
std::move(*impl_).RestoreToRegistry();
344345
delete impl_;
345346
}
346347

0 commit comments

Comments
 (0)