forked from OSchip/llvm-project
Fix for PR18735 - self-assignment for map/multimap gives incorrect results in C++03
llvm-svn: 201021
This commit is contained in:
parent
57420b320c
commit
74cf6ff5e5
|
@ -884,10 +884,12 @@ public:
|
|||
#if __cplusplus >= 201103L
|
||||
__tree_ = __m.__tree_;
|
||||
#else
|
||||
if (this != &__m) {
|
||||
__tree_.clear();
|
||||
__tree_.value_comp() = __m.__tree_.value_comp();
|
||||
__tree_.__copy_assign_alloc(__m.__tree_);
|
||||
insert(__m.begin(), __m.end());
|
||||
}
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -1616,10 +1618,12 @@ public:
|
|||
#if __cplusplus >= 201103L
|
||||
__tree_ = __m.__tree_;
|
||||
#else
|
||||
if (this != &__m) {
|
||||
__tree_.clear();
|
||||
__tree_.value_comp() = __m.__tree_.value_comp();
|
||||
__tree_.__copy_assign_alloc(__m.__tree_);
|
||||
insert(__m.begin(), __m.end());
|
||||
}
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -831,12 +831,14 @@ public:
|
|||
#if __cplusplus >= 201103L
|
||||
__table_ = __u.__table_;
|
||||
#else
|
||||
if (this != &__u) {
|
||||
__table_.clear();
|
||||
__table_.hash_function() = __u.__table_.hash_function();
|
||||
__table_.key_eq() = __u.__table_.key_eq();
|
||||
__table_.max_load_factor() = __u.__table_.max_load_factor();
|
||||
__table_.__copy_assign_alloc(__u.__table_);
|
||||
insert(__u.begin(), __u.end());
|
||||
}
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -1567,12 +1569,14 @@ public:
|
|||
#if __cplusplus >= 201103L
|
||||
__table_ = __u.__table_;
|
||||
#else
|
||||
if (this != &__u) {
|
||||
__table_.clear();
|
||||
__table_.hash_function() = __u.__table_.hash_function();
|
||||
__table_.key_eq() = __u.__table_.key_eq();
|
||||
__table_.max_load_factor() = __u.__table_.max_load_factor();
|
||||
__table_.__copy_assign_alloc(__u.__table_);
|
||||
insert(__u.begin(), __u.end());
|
||||
}
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,21 @@ int main()
|
|||
assert(*next(mo.begin()) == V(2, 1));
|
||||
assert(*next(mo.begin(), 2) == V(3, 1));
|
||||
}
|
||||
{
|
||||
typedef std::pair<const int, double> V;
|
||||
const V ar[] =
|
||||
{
|
||||
V(1, 1),
|
||||
V(2, 1),
|
||||
V(3, 1),
|
||||
};
|
||||
std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
|
||||
std::map<int, double> *p = &m;
|
||||
m = *p;
|
||||
|
||||
assert(m.size() == 3);
|
||||
assert(std::equal(m.begin(), m.end(), ar));
|
||||
}
|
||||
{
|
||||
typedef std::pair<const int, double> V;
|
||||
V ar[] =
|
||||
|
|
|
@ -48,6 +48,26 @@ int main()
|
|||
assert(mo.get_allocator() == A(2));
|
||||
assert(mo.key_comp() == C(5));
|
||||
}
|
||||
{
|
||||
typedef std::pair<const int, double> V;
|
||||
const V ar[] =
|
||||
{
|
||||
V(1, 1),
|
||||
V(1, 1.5),
|
||||
V(1, 2),
|
||||
V(2, 1),
|
||||
V(2, 1.5),
|
||||
V(2, 2),
|
||||
V(3, 1),
|
||||
V(3, 1.5),
|
||||
V(3, 2),
|
||||
};
|
||||
std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
|
||||
std::multimap<int, double> *p = &m;
|
||||
m = *p;
|
||||
assert(m.size() == sizeof(ar)/sizeof(ar[0]));
|
||||
assert(std::equal(m.begin(), m.end(), ar));
|
||||
}
|
||||
{
|
||||
typedef std::pair<const int, double> V;
|
||||
V ar[] =
|
||||
|
|
|
@ -68,6 +68,26 @@ int main()
|
|||
assert(*next(mo.begin(), 7) == 3);
|
||||
assert(*next(mo.begin(), 8) == 3);
|
||||
}
|
||||
{
|
||||
typedef int V;
|
||||
const V ar[] =
|
||||
{
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
3
|
||||
};
|
||||
std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
|
||||
std::multiset<int> *p = &m;
|
||||
m = *p;
|
||||
assert(m.size() == 9);
|
||||
assert(std::equal(m.begin(), m.end(), ar));
|
||||
}
|
||||
{
|
||||
typedef int V;
|
||||
V ar[] =
|
||||
|
|
|
@ -56,6 +56,21 @@ int main()
|
|||
assert(*next(mo.begin()) == 2);
|
||||
assert(*next(mo.begin(), 2) == 3);
|
||||
}
|
||||
{
|
||||
typedef int V;
|
||||
const V ar[] =
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
|
||||
std::set<int> *p = &m;
|
||||
m = *p;
|
||||
|
||||
assert(m.size() == 3);
|
||||
assert(std::equal(m.begin(), m.end(), ar));
|
||||
}
|
||||
{
|
||||
typedef int V;
|
||||
V ar[] =
|
||||
|
|
|
@ -72,6 +72,24 @@ int main()
|
|||
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
|
||||
assert(c.max_load_factor() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::unordered_map<int, std::string> C;
|
||||
typedef std::pair<const int, std::string> P;
|
||||
const P a[] =
|
||||
{
|
||||
P(1, "one"),
|
||||
P(2, "two"),
|
||||
P(3, "three"),
|
||||
P(4, "four"),
|
||||
P(1, "four"),
|
||||
P(2, "four"),
|
||||
};
|
||||
C c(a, a + sizeof(a)/sizeof(a[0]));
|
||||
C *p = &c;
|
||||
c = *p;
|
||||
assert(c.size() == 4);
|
||||
assert(std::is_permutation(c.begin(), c.end(), a));
|
||||
}
|
||||
{
|
||||
typedef other_allocator<std::pair<const int, std::string> > A;
|
||||
typedef std::unordered_map<int, std::string,
|
||||
|
|
|
@ -86,6 +86,24 @@ int main()
|
|||
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
|
||||
assert(c.max_load_factor() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::unordered_multimap<int, std::string> C;
|
||||
typedef std::pair<const int, std::string> P;
|
||||
const P a[] =
|
||||
{
|
||||
P(1, "one"),
|
||||
P(2, "two"),
|
||||
P(3, "three"),
|
||||
P(4, "four"),
|
||||
P(1, "four"),
|
||||
P(2, "four"),
|
||||
};
|
||||
C c(a, a+sizeof(a)/sizeof(a[0]));
|
||||
C *p = &c;
|
||||
c = *p;
|
||||
assert(c.size() == 6);
|
||||
assert(std::is_permutation(c.begin(), c.end(), a));
|
||||
}
|
||||
{
|
||||
typedef other_allocator<std::pair<const int, std::string> > A;
|
||||
typedef std::unordered_multimap<int, std::string,
|
||||
|
|
|
@ -79,6 +79,25 @@ int main()
|
|||
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
|
||||
assert(c.max_load_factor() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::unordered_multiset<int> C;
|
||||
typedef int P;
|
||||
P a[] =
|
||||
{
|
||||
P(1),
|
||||
P(2),
|
||||
P(3),
|
||||
P(4),
|
||||
P(1),
|
||||
P(2)
|
||||
};
|
||||
C c(a, a + sizeof(a)/sizeof(a[0]));
|
||||
C *p = &c;
|
||||
c = *p;
|
||||
|
||||
assert(c.size() == 6);
|
||||
assert(std::is_permutation(c.begin(), c.end(), a));
|
||||
}
|
||||
{
|
||||
typedef other_allocator<int> A;
|
||||
typedef std::unordered_multiset<int,
|
||||
|
|
|
@ -71,6 +71,24 @@ int main()
|
|||
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
|
||||
assert(c.max_load_factor() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::unordered_set<int> C;
|
||||
typedef int P;
|
||||
P a[] =
|
||||
{
|
||||
P(1),
|
||||
P(2),
|
||||
P(3),
|
||||
P(4),
|
||||
P(1),
|
||||
P(2)
|
||||
};
|
||||
C c(a, a + sizeof(a)/sizeof(a[0]));
|
||||
C *p = &c;
|
||||
c = *p;
|
||||
assert(c.size() == 4);
|
||||
assert(std::is_permutation(c.begin(), c.end(), a));
|
||||
}
|
||||
{
|
||||
typedef other_allocator<int> A;
|
||||
typedef std::unordered_set<int,
|
||||
|
|
Loading…
Reference in New Issue