diff options
author | Tom Tromey <tromey@adacore.com> | 2020-04-20 11:45:06 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-04-20 11:45:06 -0600 |
commit | 0fa7617d84da8b809b14e1e2ee67474526c62021 (patch) | |
tree | c0df8e58cdc7411ed31337b87830614c9223b6a9 /gdbsupport | |
parent | 9b2c992cfa4e9911d3b54c21ced179aa4928c422 (diff) | |
download | binutils-0fa7617d84da8b809b14e1e2ee67474526c62021.zip binutils-0fa7617d84da8b809b14e1e2ee67474526c62021.tar.gz binutils-0fa7617d84da8b809b14e1e2ee67474526c62021.tar.bz2 |
Mark move constructors as "noexcept"
I recently learned that move constructors generally should be marked
"noexcept". This ensures that standard containers will move objects
when possible, rather than copy them.
This patch fixes the cases I could find. Note that implicitly-defined
or defaulted move constructors will automatically do what you'd
expect; that is, they are noexcept if all the members have noexcept
move constructors.
While doing this, I noticed a couple of odd cases where the move
constructor seemed to assume that the object being constructed could
have state requiring destruction. I've fixed these as well. See
completion_result and scoped_mmap.
gdb/ChangeLog
2020-04-20 Tom Tromey <tromey@adacore.com>
* python/python.c (struct gdbpy_event): Mark move constructor as
noexcept.
* python/py-tui.c (class gdbpy_tui_window_maker): Mark move
constructor as noexcept.
* completer.h (struct completion_result): Mark move constructor as
noexcept.
* completer.c (completion_result::completion_result): Use
initialization style. Don't call reset_match_list.
gdbsupport/ChangeLog
2020-04-20 Tom Tromey <tromey@adacore.com>
* scoped_mmap.h (scoped_mmap): Mark move constructor as noexcept.
Use initialization style. Don't call destroy.
* scoped_fd.h (class scoped_fd): Mark move constructor as
noexcept.
* gdb_ref_ptr.h (class ref_ptr): Mark move constructor as
noexcept.
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/ChangeLog | 9 | ||||
-rw-r--r-- | gdbsupport/gdb_ref_ptr.h | 2 | ||||
-rw-r--r-- | gdbsupport/scoped_fd.h | 2 | ||||
-rw-r--r-- | gdbsupport/scoped_mmap.h | 9 |
4 files changed, 14 insertions, 8 deletions
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index cd7033d..78fbbe6 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,12 @@ +2020-04-20 Tom Tromey <tromey@adacore.com> + + * scoped_mmap.h (scoped_mmap): Mark move constructor as noexcept. + Use initialization style. Don't call destroy. + * scoped_fd.h (class scoped_fd): Mark move constructor as + noexcept. + * gdb_ref_ptr.h (class ref_ptr): Mark move constructor as + noexcept. + 2020-04-13 Tom Tromey <tom@tromey.com> * event-loop.c: Move comment. Remove obsolete comment. diff --git a/gdbsupport/gdb_ref_ptr.h b/gdbsupport/gdb_ref_ptr.h index c5ef13f..de387f5 100644 --- a/gdbsupport/gdb_ref_ptr.h +++ b/gdbsupport/gdb_ref_ptr.h @@ -78,7 +78,7 @@ class ref_ptr } /* Transfer ownership from OTHER. */ - ref_ptr (ref_ptr &&other) + ref_ptr (ref_ptr &&other) noexcept : m_obj (other.m_obj) { other.m_obj = NULL; diff --git a/gdbsupport/scoped_fd.h b/gdbsupport/scoped_fd.h index f40ce8b..ec654df 100644 --- a/gdbsupport/scoped_fd.h +++ b/gdbsupport/scoped_fd.h @@ -30,7 +30,7 @@ class scoped_fd public: explicit scoped_fd (int fd = -1) noexcept : m_fd (fd) {} - scoped_fd (scoped_fd &&other) + scoped_fd (scoped_fd &&other) noexcept : m_fd (other.m_fd) { other.m_fd = -1; diff --git a/gdbsupport/scoped_mmap.h b/gdbsupport/scoped_mmap.h index bab988f..9b74383 100644 --- a/gdbsupport/scoped_mmap.h +++ b/gdbsupport/scoped_mmap.h @@ -42,13 +42,10 @@ public: destroy (); } - scoped_mmap (scoped_mmap &&rhs) + scoped_mmap (scoped_mmap &&rhs) noexcept + : m_mem (rhs.m_mem), + m_length (rhs.m_length) { - destroy (); - - m_mem = rhs.m_mem; - m_length = rhs.m_length; - rhs.m_mem = MAP_FAILED; rhs.m_length = 0; } |