Fixed the naked calls to `addressof`.

http://reviews.llvm.org/D9411

Files:
  include/memory
  
test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
  
test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
  
test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
  
test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: include/memory
===================================================================
--- include/memory
+++ include/memory
@@ -3525,7 +3525,7 @@
     {
 #endif
         for (; __f != __l; ++__f, ++__r)
-            ::new(&*__r) value_type(*__f);
+            ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
@@ -3549,7 +3549,7 @@
     {
 #endif
         for (; __n > 0; ++__f, ++__r, --__n)
-            ::new(&*__r) value_type(*__f);
+            ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
@@ -3573,7 +3573,7 @@
     {
 #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 (...)
@@ -3596,7 +3596,7 @@
     {
 #endif
         for (; __n > 0; ++__f, --__n)
-            ::new(&*__f) value_type(__x);
+            ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
Index: test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
===================================================================
--- test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
+++ test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
@@ -28,8 +28,19 @@
 
 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 @@
     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);
+        }
+    }
+    
 }
Index: test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
===================================================================
--- test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
+++ test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
@@ -28,8 +28,19 @@
 
 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 @@
     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);
+    }
+    }
 }
Index: test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
===================================================================
--- test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
+++ test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
@@ -28,8 +28,19 @@
 
 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 @@
     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);
+    }
 }
Index: test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
===================================================================
--- test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
+++ test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
@@ -27,8 +27,19 @@
 
 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 @@
     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);
+    }
+
+    }
 }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to