summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-11-26 00:54:44 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-11-26 00:54:44 +0000
commit480f5d265a4b22eac82139df8d8edcfe7ba059d0 (patch)
tree9d78f2dc5f672707e3f53e8c99668622c7a5d699 /llvm/lib/Support/SmallPtrSet.cpp
parent2664317b66283e149bd436c14659c283f17bba3a (diff)
downloadbcm5719-llvm-480f5d265a4b22eac82139df8d8edcfe7ba059d0.tar.gz
bcm5719-llvm-480f5d265a4b22eac82139df8d8edcfe7ba059d0.zip
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 llvm-svn: 195705
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index fa8d91545e7..f873d91d6e0 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -218,8 +218,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
/// CopyFrom - implement operator= from a smallptrset that has the same pointer
/// type, but may have a different small size.
void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
- if (&RHS == this)
- return;
+ assert(&RHS != this && "Self-copy should be handled by the caller.");
if (isSmall() && RHS.isSmall())
assert(CurArraySize == RHS.CurArraySize &&
@@ -256,6 +255,8 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
#if LLVM_HAS_RVALUE_REFERENCES
void SmallPtrSetImpl::MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS) {
+ assert(&RHS != this && "Self-move should be handled by the caller.");
+
if (!isSmall())
free(CurArray);
OpenPOWER on IntegriCloud