@@ -43,8 +43,6 @@ template <typename T_functor>
43
43
struct typed_slot_rep : public slot_rep
44
44
{
45
45
private:
46
- using self = typed_slot_rep<T_functor>;
47
-
48
46
/* Use an adaptor type so that arguments can be passed as const references
49
47
* through explicit template instantiation from slot_call#::call_it() */
50
48
using adaptor_type = typename adaptor_trait<T_functor>::adaptor_type;
@@ -58,13 +56,13 @@ struct typed_slot_rep : public slot_rep
58
56
* @param functor The functor contained by the new slot_rep object.
59
57
*/
60
58
inline explicit typed_slot_rep (const T_functor& functor)
61
- : slot_rep(nullptr , &destroy, &dup ), functor_(std::make_unique<adaptor_type>(functor))
59
+ : slot_rep(nullptr ), functor_(std::make_unique<adaptor_type>(functor))
62
60
{
63
61
sigc::visit_each_trackable (slot_do_bind (this ), *functor_);
64
62
}
65
63
66
64
inline typed_slot_rep (const typed_slot_rep& src)
67
- : slot_rep(src.call_, &destroy, &dup ), functor_(std::make_unique<adaptor_type>(*src.functor_))
65
+ : slot_rep(src.call_), functor_(std::make_unique<adaptor_type>(*src.functor_))
68
66
{
69
67
sigc::visit_each_trackable (slot_do_bind (this ), *functor_);
70
68
}
@@ -74,24 +72,25 @@ struct typed_slot_rep : public slot_rep
74
72
typed_slot_rep (typed_slot_rep&& src) = delete ;
75
73
typed_slot_rep& operator =(typed_slot_rep&& src) = delete ;
76
74
77
- inline ~typed_slot_rep ()
75
+ ~typed_slot_rep () override
78
76
{
79
- call_ = nullptr ;
80
- destroy_ = nullptr ;
81
- sigc::visit_each_trackable ( slot_do_unbind ( this ), *functor_ );
77
+ // Call destroy() non-virtually.
78
+ // It's unwise to make virtual calls in a constructor or destructor.
79
+ typed_slot_rep::destroy ( );
82
80
}
83
81
84
82
private:
85
83
/* * Detaches the stored functor from the other referred trackables and destroys it.
86
84
* This does not destroy the base slot_rep object.
87
85
*/
88
- static void destroy (slot_rep* data)
86
+ void destroy () override
89
87
{
90
- auto self_ = static_cast <self*>(data);
91
- self_->call_ = nullptr ;
92
- self_->destroy_ = nullptr ;
93
- sigc::visit_each_trackable (slot_do_unbind (self_), *self_->functor_ );
94
- self_->functor_ .reset (nullptr );
88
+ call_ = nullptr ;
89
+ if (functor_)
90
+ {
91
+ sigc::visit_each_trackable (slot_do_unbind (this ), *functor_);
92
+ functor_.reset (nullptr );
93
+ }
95
94
/* don't call disconnect() here: destroy() is either called
96
95
* a) from the parent itself (in which case disconnect() leads to a segfault) or
97
96
* b) from a parentless slot (in which case disconnect() does nothing)
@@ -103,7 +102,7 @@ struct typed_slot_rep : public slot_rep
103
102
* slot_rep object is registered in the referred trackables.
104
103
* @return A deep copy of the slot_rep object.
105
104
*/
106
- static slot_rep* dup (slot_rep* a_rep) { return new self (* static_cast <self*>(a_rep) ); }
105
+ slot_rep* dup () const override { return new typed_slot_rep (* this ); }
107
106
};
108
107
109
108
/* * Abstracts functor execution.
0 commit comments