This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] In test/support/test_allocator.h, fix construct() to avoid moving immovable types.
ClosedPublic

Authored by STL_MSFT on Jun 7 2016, 12:29 PM.

Details

Summary

In test/support/test_allocator.h, fix construct() to avoid moving immovable types.

This improves the allocator's conformance, and fixes compiler errors with MSVC's STL. The scenario is when the allocator is asked to construct an object of type X that's immovable (deleted copy/move ctors), but implicitly constructible from an argument type A. When perfectly forwarded, X can be (explicitly) constructed from A, and everything is fine. That's std::allocator's behavior, and the Standard's default when a user allocator's construct() doesn't exist. The previous implementation of construct() here mishandled this scenario. Passing A to this construct() would implicitly construct an X temporary, bound to (non-templated) T&&. Then construct() would attempt to move-construct X from that X temporary, but X is immovable, boom.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 59934.Jun 7 2016, 12:29 PM
STL_MSFT retitled this revision from to [libcxx] [test] In test/support/test_allocator.h, fix construct() to avoid moving immovable types..
STL_MSFT updated this object.
STL_MSFT added reviewers: mclow.lists, EricWF.
STL_MSFT added a subscriber: cfe-commits.
EricWF added inline comments.Jun 13 2016, 11:00 PM
test/support/test_allocator.h
83

#if TEST_STD_VER < 11

88

While your here this should have be ::new ((void*)p).

I learned that from you :-P

144

#if TEST_STD_VER < 11 please.

149

While your here this should have be ::new ((void*)p).

STL_MSFT updated this revision to Diff 60736.Jun 14 2016, 1:43 PM

Inspect TEST_STD_VER and cast to void* as requested. I used a static_cast to avoid triggering any old-style cast warnings.

(I also just noticed that I deleted an empty line, but was too lazy to regenerate the diff. Oops.)

EricWF accepted this revision.Jun 14 2016, 6:58 PM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Jun 14 2016, 6:58 PM
EricWF closed this revision.Jun 14 2016, 7:00 PM