[libsigc++2] trackable: move assignment operator: null the src.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigc++2] trackable: move assignment operator: null the src.
- Date: Tue, 1 Sep 2015 13:47:49 +0000 (UTC)
commit ea858520f2f3d4825942d01eeeb0b1e834aef2b1
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Sep 1 15:43:03 2015 +0200
trackable: move assignment operator: null the src.
sigc++/trackable.cc | 2 +
tests/test_trackable_move.cc | 66 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/sigc++/trackable.cc b/sigc++/trackable.cc
index 83c87cb..e261697 100644
--- a/sigc++/trackable.cc
+++ b/sigc++/trackable.cc
@@ -58,6 +58,8 @@ trackable& trackable::operator=(trackable&& src)
callback_list_ = std::move(src.callback_list_);
+ src.callback_list_ = nullptr;
+
return *this;
}
diff --git a/tests/test_trackable_move.cc b/tests/test_trackable_move.cc
new file mode 100644
index 0000000..41d7aa4
--- /dev/null
+++ b/tests/test_trackable_move.cc
@@ -0,0 +1,66 @@
+// -*- c++ -*-
+/* Copyright 2002, The libsigc++ Development Team
+ * Assigned to public domain. Use as you wish without restriction.
+ */
+
+#include "testutilities.h"
+#include <sstream>
+#include <cstdlib>
+#include <sigc++/trackable.h>
+#include <sigc++/functors/slot.h>
+#include <sigc++/functors/mem_fun.h>
+
+namespace
+{
+std::ostringstream result_stream;
+
+class my_class: public sigc::trackable
+{
+public:
+
+ my_class(const myclass& src) = delete;
+ my_class& operator=(const myclass& src) = delete;
+
+ my_class(myclass&& src)
+ : sigc::trackable(std::move(src)),
+ i(std::move(src.i);
+ {
+ }
+
+ my_class& operator=(myclass&& src)
+ {
+ sigc::trackable::operator=(std::move(src));
+ i = std::move(src.i);
+ }
+
+ int i;
+
+ void foo()
+ {
+ result_stream << i;
+ }
+};
+
+} // end anonymous namespace
+
+int main(int argc, char* argv[])
+{
+ auto util = TestUtilities::get_instance();
+
+ if (!util->check_command_args(argc, argv))
+ return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
+
+ sigc::slot<void> sl;
+ {
+ my_class t;
+ t.i = 10;
+ sl = sigc::mem_fun0(&t, &my_class::foo);
+ sl();
+ util->check_result(result_stream, "10");
+ }
+
+ sl();
+ util->check_result(result_stream, "");
+
+ return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]