[Bf-blender-cvs] [e44045745d5] master: BLI: don't pass const pointers to placement new operator

Jacques Lucke noreply at git.blender.org
Thu Jun 11 15:38:19 CEST 2020


Commit: e44045745d51622513f5733686f78db65d160263
Author: Jacques Lucke
Date:   Thu Jun 11 15:36:01 2020 +0200
Branches: master
https://developer.blender.org/rBe44045745d51622513f5733686f78db65d160263

BLI: don't pass const pointers to placement new operator

This resulted in compile errors.

===================================================================

M	source/blender/blenlib/BLI_linear_allocator.hh
M	source/blender/blenlib/BLI_map.hh
M	source/blender/blenlib/BLI_map_slots.hh
M	source/blender/blenlib/BLI_memory_utils.hh
M	source/blender/blenlib/BLI_optional.hh
M	source/blender/blenlib/BLI_set_slots.hh

===================================================================

diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh
index f968f9f15ce..2a0dc939cb9 100644
--- a/source/blender/blenlib/BLI_linear_allocator.hh
+++ b/source/blender/blenlib/BLI_linear_allocator.hh
@@ -171,7 +171,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
     MutableSpan<T *> pointers = void_pointers.cast<T *>();
 
     for (uint i : IndexRange(n)) {
-      new (pointers[i]) T(std::forward<Args>(args)...);
+      new ((void *)pointers[i]) T(std::forward<Args>(args)...);
     }
 
     return pointers;
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh
index 4fc9f98d835..f20f7b47647 100644
--- a/source/blender/blenlib/BLI_map.hh
+++ b/source/blender/blenlib/BLI_map.hh
@@ -1175,7 +1175,7 @@ class Map {
   bool add_overwrite__impl(ForwardKey &&key, ForwardValue &&value, uint32_t hash)
   {
     auto create_func = [&](Value *ptr) {
-      new (ptr) Value(std::forward<ForwardValue>(value));
+      new ((void *)ptr) Value(std::forward<ForwardValue>(value));
       return true;
     };
     auto modify_func = [&](Value *ptr) {
diff --git a/source/blender/blenlib/BLI_map_slots.hh b/source/blender/blenlib/BLI_map_slots.hh
index 9ea2c4cad89..97d3baf0c83 100644
--- a/source/blender/blenlib/BLI_map_slots.hh
+++ b/source/blender/blenlib/BLI_map_slots.hh
@@ -84,8 +84,8 @@ template<typename Key, typename Value> class SimpleMapSlot {
   {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
-      new (this->key()) Key(*other.key());
-      new (this->value()) Value(*other.value());
+      new ((void *)this->key()) Key(*other.key());
+      new ((void *)this->value()) Value(*other.value());
     }
   }
 
@@ -98,8 +98,8 @@ template<typename Key, typename Value> class SimpleMapSlot {
   {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
-      new (this->key()) Key(std::move(*other.key()));
-      new (this->value()) Value(std::move(*other.value()));
+      new ((void *)this->key()) Key(std::move(*other.key()));
+      new ((void *)this->value()) Value(std::move(*other.value()));
     }
   }
 
@@ -170,8 +170,8 @@ template<typename Key, typename Value> class SimpleMapSlot {
     BLI_assert(!this->is_occupied());
     BLI_assert(other.is_occupied());
     m_state = Occupied;
-    new (this->key()) Key(std::move(*other.key()));
-    new (this->value()) Value(std::move(*other.value()));
+    new ((void *)this->key()) Key(std::move(*other.key()));
+    new ((void *)this->value()) Value(std::move(*other.value()));
     other.key()->~Key();
     other.value()->~Value();
   }
@@ -198,7 +198,7 @@ template<typename Key, typename Value> class SimpleMapSlot {
   {
     BLI_assert(!this->is_occupied());
     this->occupy_without_value(std::forward<ForwardKey>(key), hash);
-    new (this->value()) Value(std::forward<ForwardValue>(value));
+    new ((void *)this->value()) Value(std::forward<ForwardValue>(value));
   }
 
   /**
@@ -209,7 +209,7 @@ template<typename Key, typename Value> class SimpleMapSlot {
   {
     BLI_assert(!this->is_occupied());
     m_state = Occupied;
-    new (this->key()) Key(std::forward<ForwardKey>(key));
+    new ((void *)this->key()) Key(std::forward<ForwardKey>(key));
   }
 
   /**
@@ -251,14 +251,14 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot
   IntrusiveMapSlot(const IntrusiveMapSlot &other) : m_key(other.m_key)
   {
     if (KeyInfo::is_not_empty_or_removed(m_key)) {
-      new (this->value()) Value(*other.value());
+      new ((void *)this->value()) Value(*other.value());
     }
   }
 
   IntrusiveMapSlot(IntrusiveMapSlot &&other) noexcept : m_key(other.m_key)
   {
     if (KeyInfo::is_not_empty_or_removed(m_key)) {
-      new (this->value()) Value(std::move(*other.value()));
+      new ((void *)this->value()) Value(std::move(*other.value()));
     }
   }
 
@@ -303,7 +303,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot
     BLI_assert(!this->is_occupied());
     BLI_assert(other.is_occupied());
     m_key = std::move(other.m_key);
-    new (this->value()) Value(std::move(*other.value()));
+    new ((void *)this->value()) Value(std::move(*other.value()));
     other.m_key.~Key();
     other.value()->~Value();
   }
@@ -321,7 +321,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot
     BLI_assert(!this->is_occupied());
     BLI_assert(KeyInfo::is_not_empty_or_removed(key));
     this->occupy_without_value(std::forward<ForwardKey>(key), hash);
-    new (this->value()) Value(std::forward<ForwardValue>(value));
+    new ((void *)this->value()) Value(std::forward<ForwardValue>(value));
   }
 
   template<typename ForwardKey> void occupy_without_value(ForwardKey &&key, uint32_t UNUSED(hash))
diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh
index c317376fe8e..55dca98fb07 100644
--- a/source/blender/blenlib/BLI_memory_utils.hh
+++ b/source/blender/blenlib/BLI_memory_utils.hh
@@ -46,7 +46,7 @@ template<typename T> void default_construct_n(T *ptr, uint n)
   }
 
   for (uint i = 0; i < n; i++) {
-    new (ptr + i) T;
+    new ((void *)(ptr + i)) T;
   }
 }
 
@@ -102,7 +102,7 @@ template<typename T> void initialized_copy_n(const T *src, uint n, T *dst)
 template<typename T> void uninitialized_copy_n(const T *src, uint n, T *dst)
 {
   for (uint i = 0; i < n; i++) {
-    new (dst + i) T(src[i]);
+    new ((void *)(dst + i)) T(src[i]);
   }
 }
 
@@ -136,7 +136,7 @@ template<typename T> void initialized_move_n(T *src, uint n, T *dst)
 template<typename T> void uninitialized_move_n(T *src, uint n, T *dst)
 {
   for (uint i = 0; i < n; i++) {
-    new (dst + i) T(std::move(src[i]));
+    new ((void *)(dst + i)) T(std::move(src[i]));
   }
 }
 
@@ -200,7 +200,7 @@ template<typename T> void initialized_fill_n(T *dst, uint n, const T &value)
 template<typename T> void uninitialized_fill_n(T *dst, uint n, const T &value)
 {
   for (uint i = 0; i < n; i++) {
-    new (dst + i) T(value);
+    new ((void *)(dst + i)) T(value);
   }
 }
 
diff --git a/source/blender/blenlib/BLI_optional.hh b/source/blender/blenlib/BLI_optional.hh
index b5f98d6fa97..2e6b66d0eac 100644
--- a/source/blender/blenlib/BLI_optional.hh
+++ b/source/blender/blenlib/BLI_optional.hh
@@ -121,7 +121,7 @@ template<typename T> class Optional {
       this->value() = value;
     }
     else {
-      new (this->value_ptr()) T(value);
+      new ((void *)this->value_ptr()) T(value);
       m_set = true;
     }
   }
@@ -132,7 +132,7 @@ template<typename T> class Optional {
       this->value() = std::move(value);
     }
     else {
-      new (this->value_ptr()) T(std::move(value));
+      new ((void *)this->value_ptr()) T(std::move(value));
       m_set = true;
     }
   }
@@ -140,14 +140,14 @@ template<typename T> class Optional {
   void set_new(const T &value)
   {
     BLI_assert(!m_set);
-    new (this->value_ptr()) T(value);
+    new ((void *)this->value_ptr()) T(value);
     m_set = true;
   }
 
   void set_new(T &&value)
   {
     BLI_assert(!m_set);
-    new (this->value_ptr()) T(std::move(value));
+    new ((void *)this->value_ptr()) T(std::move(value));
     m_set = true;
   }
 
diff --git a/source/blender/blenlib/BLI_set_slots.hh b/source/blender/blenlib/BLI_set_slots.hh
index 15f56f2450e..581e70ce628 100644
--- a/source/blender/blenlib/BLI_set_slots.hh
+++ b/source/blender/blenlib/BLI_set_slots.hh
@@ -80,7 +80,7 @@ template<typename Key> class SimpleSetSlot {
   {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
-      new (this->key()) Key(*other.key());
+      new ((void *)this->key()) Key(*other.key());
     }
   }
 
@@ -93,7 +93,7 @@ template<typename Key> class SimpleSetSlot {
   {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
-      new (this->key()) Key(std::move(*other.key()));
+      new ((void *)this->key()) Key(std::move(*other.key()));
     }
   }
 
@@ -148,7 +148,7 @@ template<typename Key> class SimpleSetSlot {
     BLI_assert(!this->is_occupied());
     BLI_assert(other.is_occupied());
     m_state = Occupied;
-    new (this->key()) Key(std::move(*other.key()));
+    new ((void *)this->key()) Key(std::move(*other.key()));
     other.key()->~Key();
   }
 
@@ -173,7 +173,7 @@ template<typename Key> class SimpleSetSlot {
   {
     BLI_assert(!this->is_occupied());
     m_state = Occupied;
-    new (this->key()) Key(std::forward<ForwardKey>(key));
+    new ((void *)this->key()) Key(std::forward<ForwardKey>(key));
   }
 
   /**
@@ -221,7 +221,7 @@ template<typename Key> class HashedSetSlot {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
       m_hash = other.m_hash;
-      new (this->key()) Key(*other.key());
+      new ((void *)this->key()) Key(*other.key());
     }
   }
 
@@ -230,7 +230,7 @@ template<typename Key> class HashedSetSlot {
     m_state = other.m_state;
     if (other.m_state == Occupied) {
       m_hash = other.m_hash;
-      new (this->key()) Key(std::move(*other.key()));
+      new ((void *)this->key()) Key(std::move(*other.key()));
     }
   }
 
@@ -266,7 +266,7 @@ template<typename Key> class HashedSetSlot {
     BLI_assert(other.is_occupied());
     m_state = Occupied;
     m_hash = hash;
-    new (this->key()) Key(std::move(*other.key()));
+    new ((void *)this->key()) Key(std::move(*other.key()));
     other.key()->~Key();
   }
 
@@ -287,7 +287,7 @@ template<typename Key> class HashedSetSlot {
     BLI_assert(!this->is_occupied());
     m_state = Occupied;
     m_hash = hash;
-    new (this->key()) Key(std::forward<ForwardKey>(key));
+    new ((void *)this->key()) Key(std::forward<ForwardKey>(key));
   }
 
   void remove()



More information about the Bf-blender-cvs mailing list