[libcxx] r237699 - Implement LWG2433: uninitialized_copy()/etc. should tolerate overloaded operator&
Marshall Clow
mclow.lists at gmail.com
Tue May 19 08:01:48 PDT 2015
Author: marshall
Date: Tue May 19 10:01:48 2015
New Revision: 237699
URL: http://llvm.org/viewvc/llvm-project?rev=237699&view=rev
Log:
Implement LWG2433: uninitialized_copy()/etc. should tolerate overloaded operator&
Modified:
libcxx/trunk/include/memory
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue May 19 10:01:48 2015
@@ -3527,8 +3527,8 @@ uninitialized_copy(_InputIterator __f, _
try
{
#endif
- for (; __f != __l; ++__f, ++__r)
- ::new(&*__r) value_type(*__f);
+ for (; __f != __l; ++__f, (void) ++__r)
+ ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -3551,8 +3551,8 @@ uninitialized_copy_n(_InputIterator __f,
try
{
#endif
- for (; __n > 0; ++__f, ++__r, --__n)
- ::new(&*__r) value_type(*__f);
+ for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
+ ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -3576,7 +3576,7 @@ uninitialized_fill(_ForwardIterator __f,
{
#endif
for (; __f != __l; ++__f)
- ::new(&*__f) value_type(__x);
+ ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@@ -3598,8 +3598,8 @@ uninitialized_fill_n(_ForwardIterator __
try
{
#endif
- for (; __n > 0; ++__f, --__n)
- ::new(&*__f) value_type(__x);
+ for (; __n > 0; ++__f, (void) --__n)
+ ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
Modified: libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp Tue May 19 10:01:48 2015
@@ -28,8 +28,19 @@ struct B
int B::count_ = 0;
+struct Nasty
+{
+ Nasty() : i_ ( counter_++ ) {}
+ Nasty * operator &() const { return NULL; }
+ int i_;
+ static int counter_;
+};
+
+int Nasty::counter_ = 0;
+
int main()
{
+ {
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
@@ -48,4 +59,17 @@ int main()
std::uninitialized_copy(b, b+2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ }
+ {
+ const int N = 5;
+ char pool[sizeof(Nasty)*N] = {0};
+ Nasty * p = (Nasty *) pool;
+ Nasty arr[N];
+ std::uninitialized_copy(arr, arr+N, p);
+ for (int i = 0; i < N; ++i) {
+ assert(arr[i].i_ == i);
+ assert( p[i].i_ == i);
+ }
+ }
+
}
Modified: libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp Tue May 19 10:01:48 2015
@@ -28,8 +28,19 @@ struct B
int B::count_ = 0;
+struct Nasty
+{
+ Nasty() : i_ ( counter_++ ) {}
+ Nasty * operator &() const { return NULL; }
+ int i_;
+ static int counter_;
+};
+
+int Nasty::counter_ = 0;
+
int main()
{
+ {
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
@@ -48,4 +59,16 @@ int main()
std::uninitialized_copy_n(b, 2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ }
+ {
+ const int N = 5;
+ char pool[sizeof(Nasty)*N] = {0};
+ Nasty * p = (Nasty *) pool;
+ Nasty arr[N];
+ std::uninitialized_copy_n(arr, N, p);
+ for (int i = 0; i < N; ++i) {
+ assert(arr[i].i_ == i);
+ assert( p[i].i_ == i);
+ }
+ }
}
Modified: libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp Tue May 19 10:01:48 2015
@@ -27,8 +27,19 @@ struct B
int B::count_ = 0;
+struct Nasty
+{
+ Nasty() : i_ ( counter_++ ) {}
+ Nasty * operator &() const { return NULL; }
+ int i_;
+ static int counter_;
+};
+
+int Nasty::counter_ = 0;
+
int main()
{
+ {
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
@@ -47,4 +58,18 @@ int main()
assert(r == bp + 2);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ }
+ {
+ {
+ const int N = 5;
+ char pool[N*sizeof(Nasty)] = {0};
+ Nasty* bp = (Nasty*)pool;
+
+ Nasty::counter_ = 23;
+ std::uninitialized_fill_n(bp, N, Nasty());
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].i_ == 23);
+ }
+
+ }
}
Modified: libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp Tue May 19 10:01:48 2015
@@ -28,8 +28,19 @@ struct B
int B::count_ = 0;
+struct Nasty
+{
+ Nasty() : i_ ( counter_++ ) {}
+ Nasty * operator &() const { return NULL; }
+ int i_;
+ static int counter_;
+};
+
+int Nasty::counter_ = 0;
+
int main()
{
+ {
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
@@ -47,4 +58,15 @@ int main()
std::uninitialized_fill(bp, bp+2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ }
+ {
+ const int N = 5;
+ char pool[N*sizeof(Nasty)] = {0};
+ Nasty* bp = (Nasty*)pool;
+
+ Nasty::counter_ = 23;
+ std::uninitialized_fill(bp, bp+N, Nasty());
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].i_ == 23);
+ }
}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=237699&r1=237698&r2=237699&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue May 19 10:01:48 2015
@@ -120,7 +120,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2425">2425</td><td>operator delete(void*, size_t) doesn't invalidate pointers sufficiently</td><td>Lenexa</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2427">2427</td><td>Container adaptors as sequence containers, redux</td><td>Lenexa</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2428">2428</td><td>"External declaration" used without being defined</td><td>Lenexa</td><td>Complete</td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2433">2433</td><td>uninitialized_copy()/etc. should tolerate overloaded operator&</td><td>Lenexa</td><td></td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2433">2433</td><td>uninitialized_copy()/etc. should tolerate overloaded operator&</td><td>Lenexa</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2434">2434</td><td>shared_ptr::use_count() is efficient</td><td>Lenexa</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2437">2437</td><td>iterator_traits::reference can and can't be void</td><td>Lenexa</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2438">2438</td><td>std::iterator inheritance shouldn't be mandated</td><td>Lenexa</td><td>Complete</td></tr>
More information about the cfe-commits
mailing list