• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisão0fa7617d84da8b809b14e1e2ee67474526c62021 (tree)
Hora2020-04-21 02:45:06
AutorTom Tromey <tromey@adac...>
CommiterTom Tromey

Mensagem de Log

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.

Mudança Sumário

Diff

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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+
112 2020-04-20 Mihails Strasuns <mihails.strasuns@intel.com>
213
314 * MAINTAINERS (Write After Approval): Add myself.
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -2327,15 +2327,11 @@ completion_result::~completion_result ()
23272327
23282328 /* See completer.h */
23292329
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)
23312333 {
2332- if (this == &rhs)
2333- return;
2334-
2335- reset_match_list ();
2336- match_list = rhs.match_list;
23372334 rhs.match_list = NULL;
2338- number_matches = rhs.number_matches;
23392335 rhs.number_matches = 0;
23402336 }
23412337
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -242,7 +242,7 @@ struct completion_result
242242 DISABLE_COPY_AND_ASSIGN (completion_result);
243243
244244 /* Move a result. */
245- completion_result (completion_result &&rhs);
245+ completion_result (completion_result &&rhs) noexcept;
246246
247247 /* Release ownership of the match list array. */
248248 char **release_match_list ();
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -233,7 +233,7 @@ public:
233233
234234 ~gdbpy_tui_window_maker ();
235235
236- gdbpy_tui_window_maker (gdbpy_tui_window_maker &&other)
236+ gdbpy_tui_window_maker (gdbpy_tui_window_maker &&other) noexcept
237237 : m_constr (std::move (other.m_constr))
238238 {
239239 }
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -975,7 +975,7 @@ struct gdbpy_event
975975 {
976976 }
977977
978- gdbpy_event (gdbpy_event &&other)
978+ gdbpy_event (gdbpy_event &&other) noexcept
979979 : m_func (other.m_func)
980980 {
981981 other.m_func = nullptr;
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -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+
110 2020-04-13 Tom Tromey <tom@tromey.com>
211
312 * event-loop.c: Move comment. Remove obsolete comment.
--- a/gdbsupport/gdb_ref_ptr.h
+++ b/gdbsupport/gdb_ref_ptr.h
@@ -78,7 +78,7 @@ class ref_ptr
7878 }
7979
8080 /* Transfer ownership from OTHER. */
81- ref_ptr (ref_ptr &&other)
81+ ref_ptr (ref_ptr &&other) noexcept
8282 : m_obj (other.m_obj)
8383 {
8484 other.m_obj = NULL;
--- a/gdbsupport/scoped_fd.h
+++ b/gdbsupport/scoped_fd.h
@@ -30,7 +30,7 @@ class scoped_fd
3030 public:
3131 explicit scoped_fd (int fd = -1) noexcept : m_fd (fd) {}
3232
33- scoped_fd (scoped_fd &&other)
33+ scoped_fd (scoped_fd &&other) noexcept
3434 : m_fd (other.m_fd)
3535 {
3636 other.m_fd = -1;
--- a/gdbsupport/scoped_mmap.h
+++ b/gdbsupport/scoped_mmap.h
@@ -42,13 +42,10 @@ public:
4242 destroy ();
4343 }
4444
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)
4648 {
47- destroy ();
48-
49- m_mem = rhs.m_mem;
50- m_length = rhs.m_length;
51-
5249 rhs.m_mem = MAP_FAILED;
5350 rhs.m_length = 0;
5451 }