Skip to content

Commit 138510d

Browse files
AIGRIND-LLCmurraycu
authored andcommitted
Empty connections can be safely copied now
Copy constructor and `operator=` could fail if `src` was empty. ``` sigc::connection con1; sigc::connection con2(con1); // failed ``` ``` sigc::connection con3; sigc::connection con4; con3 = con4; // failed ```
1 parent 299d98a commit 138510d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sigc++/weak_raw_ptr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct weak_raw_ptr : public sigc::notifiable
5050
inline weak_raw_ptr(const weak_raw_ptr& src) noexcept
5151
: p_(src.p_)
5252
{
53-
p_->add_destroy_notify_callback(this, &notify_object_invalidated);
53+
if (p_)
54+
p_->add_destroy_notify_callback(this, &notify_object_invalidated);
5455
}
5556

5657
inline weak_raw_ptr& operator=(const weak_raw_ptr& src) noexcept
@@ -60,7 +61,9 @@ struct weak_raw_ptr : public sigc::notifiable
6061
}
6162

6263
p_ = src.p_;
63-
p_->add_destroy_notify_callback(this, &notify_object_invalidated);
64+
65+
if (p_)
66+
p_->add_destroy_notify_callback(this, &notify_object_invalidated);
6467

6568
return *this;
6669
}

0 commit comments

Comments
 (0)