Skip to content

Commit 18a9f6d

Browse files
author
Kjell Ahlstedt
committed
slot and signal: Add missing move constructors and move assignments
* sigc++/functors/macros/slot.h.m4: Add move operators for slot<>. * sigc++/macros/signal.h.m4: Add move operators for signal#<> and signal<>. * tests/test_signal_move.cc: * tests/test_slot_move.cc: Test that the source objects are empty. Bug #756484.
1 parent b53b58b commit 18a9f6d

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

sigc++/functors/macros/slot.h.m4

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,43 @@ public:
215215
slot(const T_functor& _A_func)
216216
: parent_type(_A_func) {}
217217
218-
// Without reinterpret_cast (or static_cast) parent_type(const T_functor& _A_func)
218+
// Without static_cast parent_type(const T_functor& _A_func)
219219
// is called instead of the copy constructor.
220220
/** Constructs a slot, copying an existing one.
221221
* @param src The existing slot to copy.
222222
*/
223223
slot(const slot& src)
224-
: parent_type(reinterpret_cast<const parent_type&>(src)) {}
224+
: parent_type(static_cast<const parent_type&>(src)) {}
225+
226+
// Without static_cast parent_type(const T_functor& _A_func)
227+
// is called instead of the move constructor.
228+
/** Constructs a slot, moving an existing one.
229+
* If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
230+
* @param src The existing slot to move or copy.
231+
*/
232+
slot(slot&& src)
233+
: parent_type(std::move(static_cast<parent_type&>(src))) {}
234+
235+
/** Overrides this slot, making a copy from another slot.
236+
* @param src The slot from which to make a copy.
237+
* @return @p this.
238+
*/
239+
slot& operator=(const slot& src)
240+
{
241+
parent_type::operator=(src);
242+
return *this;
243+
}
244+
245+
/** Overrides this slot, making a move from another slot.
246+
* If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
247+
* @param src The slot from which to move or copy.
248+
* @return @p this.
249+
*/
250+
slot& operator=(slot&& src)
251+
{
252+
parent_type::operator=(std::move(src));
253+
return *this;
254+
}
225255
};
226256
227257
ifelse($1, $2,[dnl

sigc++/macros/signal.h.m4

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ FOR(1, $1,[
391391
392392
signal$1(const signal$1& src)
393393
: signal_base(src) {}
394+
395+
signal$1(signal$1&& src)
396+
: signal_base(std::move(src)) {}
397+
398+
signal$1& operator=(const signal$1& src)
399+
{
400+
signal_base::operator=(src);
401+
return *this;
402+
}
403+
404+
signal$1& operator=(signal$1&& src)
405+
{
406+
signal_base::operator=(std::move(src));
407+
return *this;
408+
}
394409
};
395410
396411
])
@@ -512,8 +527,24 @@ ifelse($1, $2,[dnl
512527
};
513528
514529
signal() {}
530+
515531
signal(const signal& src)
516532
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(src) {}
533+
534+
signal(signal&& src)
535+
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(std::move(src)) {}
536+
537+
signal& operator=(const signal& src)
538+
{
539+
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(src);
540+
return *this;
541+
}
542+
543+
signal& operator=(signal&& src)
544+
{
545+
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(std::move(src));
546+
return *this;
547+
}
517548
};
518549
519550
])

tests/test_signal_move.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ int main(int argc, char* argv[])
3737

3838
//Test the move constructor:
3939
sigc::signal<int, int> sig2(std::move(sig));
40-
//sig(-2); Add when more move constructors have been added
40+
sig(-2);
4141
sig2(2);
4242
util->check_result(result_stream, "foo(int 2)");
4343

4444
//Test the move assignment operator:
4545
sigc::signal<int, int> sig3;
4646
sig3 = std::move(sig2);
47-
//sig2(-3); Add when more move assignment operators have been added
47+
sig2(-3);
4848
sig3(3);
4949
util->check_result(result_stream, "foo(int 3)");
5050

tests/test_slot_move.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ int main(int argc, char* argv[])
5353

5454
// test move constructor:
5555
sigc::slot<void,int> s2(std::move(s1));
56-
//s1(-2); Add when more move constructors have been added
56+
s1(-2);
5757
s2(2);
5858
util->check_result(result_stream, "foo(int 2)");
5959

6060
// test move assignment:
6161
sigc::slot<void,int> s3;
6262
s3 = std::move(s2);
63-
//s2(-3); Add when more move assignment operators have been added
63+
s2(-3);
6464
s3(3);
6565
util->check_result(result_stream, "foo(int 3)");
6666

0 commit comments

Comments
 (0)