[cfe-dev] libc++ std::map self-assignment bug
Kal
b17c0de at gmail.com
Thu Nov 28 17:19:44 PST 2013
Hi Howard, etc,
libc++3.4 (rc1/trunk) std::map doesn't support self-assignment for std <
c++11. The relevant code is:
_LIBCPP_INLINE_VISIBILITY
map& operator=(const map& __m)
{
#if __cplusplus >= 201103L
__tree_ = __m.__tree_;
#else
__tree_.clear();
__tree_.value_comp() = __m.__tree_.value_comp();
__tree_.__copy_assign_alloc(__m.__tree_);
insert(__m.begin(), __m.end());
#endif
return *this;
}
Maybe should be like:
_LIBCPP_INLINE_VISIBILITY
map& operator=(const map& __m)
{
#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;
}
I see the same issue with unordered_map& operator=(const unordered_map&
__u).
Thanks!
Kal
More information about the cfe-dev
mailing list