diff --git a/llvm/include/llvm/Support/SaveAndRestore.h b/llvm/include/llvm/Support/SaveAndRestore.h --- a/llvm/include/llvm/Support/SaveAndRestore.h +++ b/llvm/include/llvm/Support/SaveAndRestore.h @@ -20,11 +20,12 @@ /// A utility class that uses RAII to save and restore the value of a variable. template struct SaveAndRestore { SaveAndRestore(T &X) : X(X), OldValue(X) {} - SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) { - X = NewValue; + SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) { X = NewValue; } + SaveAndRestore(T &X, T &&NewValue) : X(X), OldValue(std::move(X)) { + X = std::move(NewValue); } - ~SaveAndRestore() { X = OldValue; } - T get() { return OldValue; } + ~SaveAndRestore() { X = std::move(OldValue); } + const T &get() { return OldValue; } private: T &X;