Home Dashboard Directory Help

Move constructors of all containers are not implemented correctly by jhansw



Sign in
to vote
Type: Bug
ID: 775715
Opened: 1/3/2013 11:36:30 AM
Access Restriction: Public
User(s) can reproduce this bug


Edit: All containers are affected.

See table 99 in section 23.2.1 of ISO 14882:2011: Allocator-aware container requirement.
Given a container type X, and a r-value of type X,
the expression X u(rv) has the post-condition: "u shall have the same elements as rv had before construction; the value of get_allocator() shall be the same as the value of rv.get_allocation() before this construction"

Note that it doesn't require X::value_type to be MoveConstructible.

The move constructors of vector,deque,set,map,unordered_set,unordered_map,
multimap, and unordered_multimap in VC11 "X(_Myt&& _Right)" usually
delegates to "_Assign_rv(_Myt&& _Right)" which is implemented incorrectly in the following ways:
1) It doesn't move construct an allocator from rv
2) It requires X::value_type to be MoveInsertable into X

I think whoever implemented this didn't realise that move construction is different from move assignment for allocator-aware containers. In move assignment, the left-hand side does not have its allocator changed: that's why, if the allocators differ, the elements need to be move inserted into the left-hand side and thus requires that X::value_type be move insertable. For move construction, the allocators become the same: therefore construction is always achieved through swap without touching the elements.

Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 2/11/2013 at 3:13 PM

Thank you for reporting this issue. We have fixed this bug and the fix will be present in the next version of the Visual C++ libraries. While we were investigating this bug, we also wrote extensive tests to verify that our container implementations are correct and adhere to the new C++11 fine-grained container requirements for value types; we found a number of other issues and fixes for those issues will also be present in the next version of the Visual C++ libraries.

If you do find further issues where the Visual C++ 2012 Standard Library containers do not conform to the C++11 fine-grained container requirements, please open another Connect bug or contact me directly, just so we can verify that we've fixed the issues.

Note: Connect doesn't notify me about comments. If you have any further questions, please e-mail me.

James McNellis
Visual C++ Libraries
Posted by Microsoft on 1/3/2013 at 11:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.