Merge "Add noexcept to move constructors and assignment operators."

This commit is contained in:
Chih-hung Hsieh 2018-10-05 20:05:12 +00:00 committed by Gerrit Code Review
commit 3356ca3040
16 changed files with 45 additions and 40 deletions

View file

@ -42,14 +42,14 @@ struct Block {
}
Block(const Block& copy) = delete;
Block(Block&& move) {
Block(Block&& move) noexcept {
std::swap(data_, move.data_);
std::swap(capacity_, move.capacity_);
std::swap(size_, move.size_);
}
Block& operator=(const Block& copy) = delete;
Block& operator=(Block&& move) {
Block& operator=(Block&& move) noexcept {
clear();
std::swap(data_, move.data_);
@ -147,12 +147,10 @@ struct IOVector {
}
IOVector(const IOVector& copy) = delete;
IOVector(IOVector&& move) : IOVector() {
*this = std::move(move);
}
IOVector(IOVector&& move) noexcept : IOVector() { *this = std::move(move); }
IOVector& operator=(const IOVector& copy) = delete;
IOVector& operator=(IOVector&& move) {
IOVector& operator=(IOVector&& move) noexcept {
chain_ = std::move(move.chain_);
chain_length_ = move.chain_length_;
begin_offset_ = move.begin_offset_;

View file

@ -28,7 +28,7 @@ class ScopeGuard {
public:
ScopeGuard(F&& f) : f_(std::forward<F>(f)), active_(true) {}
ScopeGuard(ScopeGuard&& that) : f_(std::move(that.f_)), active_(that.active_) {
ScopeGuard(ScopeGuard&& that) noexcept : f_(std::move(that.f_)), active_(that.active_) {
that.active_ = false;
}

View file

@ -90,8 +90,8 @@ class unique_fd_impl final {
explicit unique_fd_impl(int fd) { reset(fd); }
~unique_fd_impl() { reset(); }
unique_fd_impl(unique_fd_impl&& other) { reset(other.release()); }
unique_fd_impl& operator=(unique_fd_impl&& s) {
unique_fd_impl(unique_fd_impl&& other) noexcept { reset(other.release()); }
unique_fd_impl& operator=(unique_fd_impl&& s) noexcept {
int fd = s.fd_;
s.fd_ = -1;
reset(fd, &s);

View file

@ -59,7 +59,8 @@ class TempDevice {
: dm_(DeviceMapper::Instance()), name_(name), valid_(false) {
valid_ = dm_.CreateDevice(name, table);
}
TempDevice(TempDevice&& other) : dm_(other.dm_), name_(other.name_), valid_(other.valid_) {
TempDevice(TempDevice&& other) noexcept
: dm_(other.dm_), name_(other.name_), valid_(other.valid_) {
other.valid_ = false;
}
~TempDevice() {
@ -103,7 +104,7 @@ class TempDevice {
TempDevice(const TempDevice&) = delete;
TempDevice& operator=(const TempDevice&) = delete;
TempDevice& operator=(TempDevice&& other) {
TempDevice& operator=(TempDevice&& other) noexcept {
name_ = other.name_;
valid_ = other.valid_;
other.valid_ = false;

View file

@ -47,9 +47,9 @@ class EventHandler {
public:
EventHandler();
EventHandler(const EventHandler&) = delete;
EventHandler(EventHandler&&);
EventHandler(EventHandler&&) noexcept;
EventHandler& operator=(const EventHandler&) = delete;
EventHandler& operator=(EventHandler&&);
EventHandler& operator=(EventHandler&&) noexcept;
~EventHandler() noexcept;
bool init();
@ -64,11 +64,11 @@ class EventHandler {
EventHandler::EventHandler() : fd_(-1) {}
EventHandler::EventHandler(EventHandler&& rval) : fd_(rval.fd_) {
EventHandler::EventHandler(EventHandler&& rval) noexcept : fd_(rval.fd_) {
rval.fd_ = -1;
}
EventHandler& EventHandler::operator=(EventHandler&& rval) {
EventHandler& EventHandler::operator=(EventHandler&& rval) noexcept {
fd_ = rval.fd_;
rval.fd_ = -1;
return *this;

View file

@ -72,7 +72,7 @@ class MapString {
explicit MapString(const std::string& str)
: alloc(new std::string(str)), str(alloc->data(), alloc->length()) {
}
MapString(MapString&& rval)
MapString(MapString&& rval) noexcept
: alloc(rval.alloc), str(rval.data(), rval.length()) {
rval.alloc = NULL;
}

View file

@ -33,12 +33,12 @@ class ScopedPipe {
}
~ScopedPipe() { Close(); }
ScopedPipe(ScopedPipe&& other) {
ScopedPipe(ScopedPipe&& other) noexcept {
SetReceiver(other.ReleaseReceiver());
SetSender(other.ReleaseSender());
}
ScopedPipe& operator=(ScopedPipe&& other) {
ScopedPipe& operator=(ScopedPipe&& other) noexcept {
SetReceiver(other.ReleaseReceiver());
SetSender(other.ReleaseSender());
return *this;

View file

@ -38,7 +38,7 @@ class Node {
Node(T* ptr, Allocator<Node> allocator)
: references_in(allocator), references_out(allocator), ptr(ptr){};
Node(Node&& rhs) = default;
Node(Node&& rhs) noexcept = default;
void Edge(Node<T>* ref) {
references_out.emplace(ref);
ref->references_in.emplace(this);

View file

@ -62,11 +62,17 @@ FileMap::FileMap(void)
}
// Move Constructor.
FileMap::FileMap(FileMap&& other)
: mFileName(other.mFileName), mBasePtr(other.mBasePtr), mBaseLength(other.mBaseLength),
mDataOffset(other.mDataOffset), mDataPtr(other.mDataPtr), mDataLength(other.mDataLength)
FileMap::FileMap(FileMap&& other) noexcept
: mFileName(other.mFileName),
mBasePtr(other.mBasePtr),
mBaseLength(other.mBaseLength),
mDataOffset(other.mDataOffset),
mDataPtr(other.mDataPtr),
mDataLength(other.mDataLength)
#if defined(__MINGW32__)
, mFileHandle(other.mFileHandle), mFileMapping(other.mFileMapping)
,
mFileHandle(other.mFileHandle),
mFileMapping(other.mFileMapping)
#endif
{
other.mFileName = nullptr;
@ -79,7 +85,7 @@ FileMap::FileMap(FileMap&& other)
}
// Move assign operator.
FileMap& FileMap::operator=(FileMap&& other) {
FileMap& FileMap::operator=(FileMap&& other) noexcept {
mFileName = other.mFileName;
mBasePtr = other.mBasePtr;
mBaseLength = other.mBaseLength;

View file

@ -52,8 +52,8 @@ class FileMap {
public:
FileMap(void);
FileMap(FileMap&& f);
FileMap& operator=(FileMap&& f);
FileMap(FileMap&& f) noexcept;
FileMap& operator=(FileMap&& f) noexcept;
/*
* Create a new mapping on an open file.

View file

@ -56,7 +56,7 @@ public:
sp(T* other); // NOLINT(implicit)
sp(const sp<T>& other);
sp(sp<T>&& other);
sp(sp<T>&& other) noexcept;
template<typename U> sp(U* other); // NOLINT(implicit)
template<typename U> sp(const sp<U>& other); // NOLINT(implicit)
template<typename U> sp(sp<U>&& other); // NOLINT(implicit)
@ -67,7 +67,7 @@ public:
sp& operator = (T* other);
sp& operator = (const sp<T>& other);
sp& operator = (sp<T>&& other);
sp& operator=(sp<T>&& other) noexcept;
template<typename U> sp& operator = (const sp<U>& other);
template<typename U> sp& operator = (sp<U>&& other);
@ -125,9 +125,8 @@ sp<T>::sp(const sp<T>& other)
m_ptr->incStrong(this);
}
template<typename T>
sp<T>::sp(sp<T>&& other)
: m_ptr(other.m_ptr) {
template <typename T>
sp<T>::sp(sp<T>&& other) noexcept : m_ptr(other.m_ptr) {
other.m_ptr = nullptr;
}
@ -169,8 +168,8 @@ sp<T>& sp<T>::operator =(const sp<T>& other) {
return *this;
}
template<typename T>
sp<T>& sp<T>::operator =(sp<T>&& other) {
template <typename T>
sp<T>& sp<T>::operator=(sp<T>&& other) noexcept {
T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
if (oldPtr) oldPtr->decStrong(this);
if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();

View file

@ -91,10 +91,10 @@ class ZipWriter {
explicit ZipWriter(FILE* f);
// Move constructor.
ZipWriter(ZipWriter&& zipWriter);
ZipWriter(ZipWriter&& zipWriter) noexcept;
// Move assignment.
ZipWriter& operator=(ZipWriter&& zipWriter);
ZipWriter& operator=(ZipWriter&& zipWriter) noexcept;
/**
* Starts a new zip entry with the given path and flags.

View file

@ -903,7 +903,7 @@ class FileWriter : public zip_archive::Writer {
return FileWriter(fd, declared_length);
}
FileWriter(FileWriter&& other)
FileWriter(FileWriter&& other) noexcept
: fd_(other.fd_),
declared_length_(other.declared_length_),
total_bytes_written_(other.total_bytes_written_) {

View file

@ -97,7 +97,7 @@ ZipWriter::ZipWriter(FILE* f)
}
}
ZipWriter::ZipWriter(ZipWriter&& writer)
ZipWriter::ZipWriter(ZipWriter&& writer) noexcept
: file_(writer.file_),
seekable_(writer.seekable_),
current_offset_(writer.current_offset_),
@ -109,7 +109,7 @@ ZipWriter::ZipWriter(ZipWriter&& writer)
writer.state_ = State::kError;
}
ZipWriter& ZipWriter::operator=(ZipWriter&& writer) {
ZipWriter& ZipWriter::operator=(ZipWriter&& writer) noexcept {
file_ = writer.file_;
seekable_ = writer.seekable_;
current_offset_ = writer.current_offset_;

View file

@ -531,7 +531,7 @@ struct TagNameKey {
name = std::string_view(alloc->c_str(), alloc->size());
}
explicit TagNameKey(TagNameKey&& rval)
explicit TagNameKey(TagNameKey&& rval) noexcept
: alloc(rval.alloc), name(rval.name.data(), rval.name.length()) {
rval.alloc = nullptr;
}

View file

@ -112,7 +112,8 @@ class KmParamSet : public keymaster_key_param_set_t {
}
}
}
KmParamSet(KmParamSet&& other) : keymaster_key_param_set_t{other.params, other.length} {
KmParamSet(KmParamSet&& other) noexcept
: keymaster_key_param_set_t{other.params, other.length} {
other.length = 0;
other.params = nullptr;
}