Fix LWG#2127: Move-construction with raw_storage_iterator.

llvm-svn: 251247
This commit is contained in:
Marshall Clow 2015-10-25 18:58:07 +00:00
parent 9be5356452
commit 2603b0758d
3 changed files with 28 additions and 5 deletions

View File

@ -1909,6 +1909,10 @@ public:
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
{::new(&*__x_) _Tp(__element); return *this;}
#if _LIBCPP_STD_VER >= 14
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
{::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
#endif
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
{raw_storage_iterator __t(*this); ++__x_; return __t;}

View File

@ -13,6 +13,8 @@
#include <type_traits>
#include <cassert>
#include <MoveOnly.h>
int A_constructed = 0;
struct A
@ -29,16 +31,33 @@ public:
int main()
{
typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
{
typedef A S;
typedef std::aligned_storage<3*sizeof(S), std::alignment_of<S>::value>::type
Storage;
Storage buffer;
std::raw_storage_iterator<A*, A> it((A*)&buffer);
std::raw_storage_iterator<S*, S> it((S*)&buffer);
assert(A_constructed == 0);
for (int i = 0; i < 3; ++i)
{
*it++ = A(i+1);
A* ap = (A*)&buffer + i;
*it++ = S(i+1);
S* ap = (S*)&buffer + i;
assert(*ap == i+1);
assert(A_constructed == i+1);
}
}
#if _LIBCPP_STD_VER >= 14
{
typedef MoveOnly S;
typedef std::aligned_storage<3*sizeof(S), std::alignment_of<S>::value>::type
Storage;
Storage buffer;
std::raw_storage_iterator<S*, S> it((S*)&buffer);
S m{1};
*it++ = std::move(m);
assert(m.get() == 0); // moved from
S *ap = (S*) &buffer;
assert(ap->get() == 1); // original value
}
#endif
}

View File

@ -152,7 +152,7 @@
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2101">2101</a></td><td>Some transformation types can produce impossible types</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2111">2111</a></td><td>Which <tt>unexpected</tt>&#47;<tt>terminate</tt> handler is called from the exception handling runtime?</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2119">2119</a></td><td>Missing <tt>hash</tt> specializations for extended integer types</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2127">2127</a></td><td>Move-construction with <tt>raw_storage_iterator</tt></td><td>Kona</td><td>Patch Ready</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2127">2127</a></td><td>Move-construction with <tt>raw_storage_iterator</tt></td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2133">2133</a></td><td>Attitude to overloaded comma for iterators</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2156">2156</a></td><td>Unordered containers' <tt>reserve(n)</tt> reserves for <tt>n-1</tt> elements</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2218">2218</a></td><td>Unclear how containers use <tt>allocator_traits::construct()</tt></td><td>Kona</td><td></td></tr>