QSharedPointer: destroy LHS on move assignment
Howard Hinnant is right: just swapping may keep a resource alive too long.
The problem with replacing swap(other) was that the naïve approach:
clear(); swap(other);
is not safe for self-assignment. Taking a cue from the default std::swap()
implementation, and the copy-swap idiom, a self-assignment-safe version is
QSharedPointer moved(std::move(other)); swap(moved);
which is to what I changed the implementation now.
Change-Id: I589fdae50ae22b95350db8250b02d983dc8487a6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
b3fc0443a0
commit
556cdac9ac
|
|
@ -332,7 +332,8 @@ public:
|
|||
}
|
||||
inline QSharedPointer &operator=(QSharedPointer &&other)
|
||||
{
|
||||
swap(other);
|
||||
QSharedPointer moved(std::move(other));
|
||||
swap(moved);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue