[cfe-dev] libc++ std::map self-assignment bug
Karen Shaeffer
shaeffer at neuralscape.com
Thu Nov 28 18:58:07 PST 2013
On Fri, Nov 29, 2013 at 02:19:44AM +0100, Kal wrote:
> 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
--- end quoted text ---
Hi Kal,
I don't speak for Howard or anyone else. But my understanding is the stl library
generally doesn't perform checks like that with the goal of best possible performance.
I see a lot of code in stdlibc++ just like that.
enjoy,
Karen
--
Karen Shaeffer Be aware: If you see an obstacle in your path,
Neuralscape Services that obstacle is your path. Zen proverb
More information about the cfe-dev
mailing list