diff options
author | AIGRIND <AIGRIND-LLC@users.noreply.github.com> | 2019-09-25 11:29:45 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2019-09-26 11:43:43 +0200 |
commit | 138510d4002a0ee866016f462e6687454757b4e8 (patch) | |
tree | 121fda150850b86aa50a5c0b0699c14f138783b2 | |
parent | 299d98ade5a460d2e81b3a29e0111c548107ebd7 (diff) | |
download | sigc++-138510d4002a0ee866016f462e6687454757b4e8.tar.gz |
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
```
-rw-r--r-- | sigc++/weak_raw_ptr.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sigc++/weak_raw_ptr.h b/sigc++/weak_raw_ptr.h index ccae1b0..816981c 100644 --- a/sigc++/weak_raw_ptr.h +++ b/sigc++/weak_raw_ptr.h @@ -50,7 +50,8 @@ struct weak_raw_ptr : public sigc::notifiable inline weak_raw_ptr(const weak_raw_ptr& src) noexcept : p_(src.p_) { - p_->add_destroy_notify_callback(this, ¬ify_object_invalidated); + if (p_) + p_->add_destroy_notify_callback(this, ¬ify_object_invalidated); } inline weak_raw_ptr& operator=(const weak_raw_ptr& src) noexcept @@ -60,7 +61,9 @@ struct weak_raw_ptr : public sigc::notifiable } p_ = src.p_; - p_->add_destroy_notify_callback(this, ¬ify_object_invalidated); + + if (p_) + p_->add_destroy_notify_callback(this, ¬ify_object_invalidated); return *this; } |