diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-11-26 00:54:44 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-11-26 00:54:44 +0000 |
commit | ffd79061ccfea4c884d4d2646992aa30cf6514a2 (patch) | |
tree | 820779ffbf112b404518d55f635d628001974851 /include | |
parent | b30824e1b97b9d2b4c8e11a5d684bef5b816b887 (diff) | |
download | llvm-ffd79061ccfea4c884d4d2646992aa30cf6514a2.tar.gz llvm-ffd79061ccfea4c884d4d2646992aa30cf6514a2.tar.bz2 llvm-ffd79061ccfea4c884d4d2646992aa30cf6514a2.tar.xz |
Lift self-copy protection up to the header file and add self-move
protection to the same layer.
This is in line with Howard's advice on how best to handle self-move
assignment as he explained on SO[1]. It also ensures that implementing
swap with move assignment continues to work in the case of self-swap.
[1]: http://stackoverflow.com/questions/9322174/move-assignment-operator-and-if-this-rhs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195705 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/SmallPtrSet.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h index c7f5e5bfc0..b52aebf7d5 100644 --- a/include/llvm/ADT/SmallPtrSet.h +++ b/include/llvm/ADT/SmallPtrSet.h @@ -293,14 +293,16 @@ public: SmallPtrSet<PtrType, SmallSize> & operator=(const SmallPtrSet<PtrType, SmallSize> &RHS) { - CopyFrom(RHS); + if (&RHS != this) + CopyFrom(RHS); return *this; } #if LLVM_HAS_RVALUE_REFERENCES SmallPtrSet<PtrType, SmallSize>& operator=(SmallPtrSet<PtrType, SmallSize> &&RHS) { - MoveFrom(SmallSizePowTwo, std::move(RHS)); + if (&RHS != this) + MoveFrom(SmallSizePowTwo, std::move(RHS)); return *this; } #endif |