GNU Binutils with patches for OS216
Revisão | 0fa7617d84da8b809b14e1e2ee67474526c62021 (tree) |
---|---|
Hora | 2020-04-21 02:45:06 |
Autor | Tom Tromey <tromey@adac...> |
Commiter | Tom Tromey |
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.
@@ -1,3 +1,14 @@ | ||
1 | +2020-04-20 Tom Tromey <tromey@adacore.com> | |
2 | + | |
3 | + * python/python.c (struct gdbpy_event): Mark move constructor as | |
4 | + noexcept. | |
5 | + * python/py-tui.c (class gdbpy_tui_window_maker): Mark move | |
6 | + constructor as noexcept. | |
7 | + * completer.h (struct completion_result): Mark move constructor as | |
8 | + noexcept. | |
9 | + * completer.c (completion_result::completion_result): Use | |
10 | + initialization style. Don't call reset_match_list. | |
11 | + | |
1 | 12 | 2020-04-20 Mihails Strasuns <mihails.strasuns@intel.com> |
2 | 13 | |
3 | 14 | * MAINTAINERS (Write After Approval): Add myself. |
@@ -2327,15 +2327,11 @@ completion_result::~completion_result () | ||
2327 | 2327 | |
2328 | 2328 | /* See completer.h */ |
2329 | 2329 | |
2330 | -completion_result::completion_result (completion_result &&rhs) | |
2330 | +completion_result::completion_result (completion_result &&rhs) noexcept | |
2331 | + : match_list (rhs.match_list), | |
2332 | + number_matches (rhs.number_matches) | |
2331 | 2333 | { |
2332 | - if (this == &rhs) | |
2333 | - return; | |
2334 | - | |
2335 | - reset_match_list (); | |
2336 | - match_list = rhs.match_list; | |
2337 | 2334 | rhs.match_list = NULL; |
2338 | - number_matches = rhs.number_matches; | |
2339 | 2335 | rhs.number_matches = 0; |
2340 | 2336 | } |
2341 | 2337 |
@@ -242,7 +242,7 @@ struct completion_result | ||
242 | 242 | DISABLE_COPY_AND_ASSIGN (completion_result); |
243 | 243 | |
244 | 244 | /* Move a result. */ |
245 | - completion_result (completion_result &&rhs); | |
245 | + completion_result (completion_result &&rhs) noexcept; | |
246 | 246 | |
247 | 247 | /* Release ownership of the match list array. */ |
248 | 248 | char **release_match_list (); |
@@ -233,7 +233,7 @@ public: | ||
233 | 233 | |
234 | 234 | ~gdbpy_tui_window_maker (); |
235 | 235 | |
236 | - gdbpy_tui_window_maker (gdbpy_tui_window_maker &&other) | |
236 | + gdbpy_tui_window_maker (gdbpy_tui_window_maker &&other) noexcept | |
237 | 237 | : m_constr (std::move (other.m_constr)) |
238 | 238 | { |
239 | 239 | } |
@@ -975,7 +975,7 @@ struct gdbpy_event | ||
975 | 975 | { |
976 | 976 | } |
977 | 977 | |
978 | - gdbpy_event (gdbpy_event &&other) | |
978 | + gdbpy_event (gdbpy_event &&other) noexcept | |
979 | 979 | : m_func (other.m_func) |
980 | 980 | { |
981 | 981 | other.m_func = nullptr; |
@@ -1,3 +1,12 @@ | ||
1 | +2020-04-20 Tom Tromey <tromey@adacore.com> | |
2 | + | |
3 | + * scoped_mmap.h (scoped_mmap): Mark move constructor as noexcept. | |
4 | + Use initialization style. Don't call destroy. | |
5 | + * scoped_fd.h (class scoped_fd): Mark move constructor as | |
6 | + noexcept. | |
7 | + * gdb_ref_ptr.h (class ref_ptr): Mark move constructor as | |
8 | + noexcept. | |
9 | + | |
1 | 10 | 2020-04-13 Tom Tromey <tom@tromey.com> |
2 | 11 | |
3 | 12 | * event-loop.c: Move comment. Remove obsolete comment. |
@@ -78,7 +78,7 @@ class ref_ptr | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | /* Transfer ownership from OTHER. */ |
81 | - ref_ptr (ref_ptr &&other) | |
81 | + ref_ptr (ref_ptr &&other) noexcept | |
82 | 82 | : m_obj (other.m_obj) |
83 | 83 | { |
84 | 84 | other.m_obj = NULL; |
@@ -30,7 +30,7 @@ class scoped_fd | ||
30 | 30 | public: |
31 | 31 | explicit scoped_fd (int fd = -1) noexcept : m_fd (fd) {} |
32 | 32 | |
33 | - scoped_fd (scoped_fd &&other) | |
33 | + scoped_fd (scoped_fd &&other) noexcept | |
34 | 34 | : m_fd (other.m_fd) |
35 | 35 | { |
36 | 36 | other.m_fd = -1; |
@@ -42,13 +42,10 @@ public: | ||
42 | 42 | destroy (); |
43 | 43 | } |
44 | 44 | |
45 | - scoped_mmap (scoped_mmap &&rhs) | |
45 | + scoped_mmap (scoped_mmap &&rhs) noexcept | |
46 | + : m_mem (rhs.m_mem), | |
47 | + m_length (rhs.m_length) | |
46 | 48 | { |
47 | - destroy (); | |
48 | - | |
49 | - m_mem = rhs.m_mem; | |
50 | - m_length = rhs.m_length; | |
51 | - | |
52 | 49 | rhs.m_mem = MAP_FAILED; |
53 | 50 | rhs.m_length = 0; |
54 | 51 | } |