[Bf-blender-cvs] [c6e70e7bacf] master: Cleanup: follow C++ type cast style guide in some files
Jacques Lucke
noreply at git.blender.org
Sun Sep 25 17:41:03 CEST 2022
Commit: c6e70e7bacf82b38ca7125d6821713a711489c0b
Author: Jacques Lucke
Date: Sun Sep 25 17:39:45 2022 +0200
Branches: master
https://developer.blender.org/rBc6e70e7bacf82b38ca7125d6821713a711489c0b
Cleanup: follow C++ type cast style guide in some files
https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast
This was discussed in https://devtalk.blender.org/t/rfc-style-guide-for-type-casts-in-c-code/25907.
===================================================================
M source/blender/blenlib/BLI_allocator.hh
M source/blender/blenlib/BLI_any.hh
M source/blender/blenlib/BLI_array.hh
M source/blender/blenlib/BLI_bit_vector.hh
M source/blender/blenlib/BLI_cpp_type_make.hh
M source/blender/blenlib/BLI_function_ref.hh
M source/blender/blenlib/BLI_generic_array.hh
M source/blender/blenlib/BLI_generic_virtual_array.hh
M source/blender/blenlib/BLI_hash.hh
M source/blender/blenlib/BLI_hash_tables.hh
M source/blender/blenlib/BLI_linear_allocator.hh
M source/blender/blenlib/BLI_map.hh
M source/blender/blenlib/BLI_math_vec_types.hh
M source/blender/blenlib/BLI_math_vector.hh
M source/blender/blenlib/BLI_memory_utils.hh
M source/blender/blenlib/BLI_mesh_intersect.hh
M source/blender/blenlib/BLI_probing_strategies.hh
M source/blender/blenlib/BLI_rand.hh
M source/blender/blenlib/BLI_resource_scope.hh
M source/blender/blenlib/BLI_set.hh
M source/blender/blenlib/BLI_span.hh
M source/blender/blenlib/BLI_string_ref.hh
M source/blender/blenlib/BLI_utildefines.h
M source/blender/blenlib/BLI_vector.hh
M source/blender/blenlib/BLI_vector_set.hh
M source/blender/blenlib/BLI_virtual_array.hh
M source/blender/blenlib/tests/BLI_linear_allocator_test.cc
M source/blender/blenlib/tests/BLI_span_test.cc
M source/blender/blenlib/tests/BLI_stack_cxx_test.cc
M source/blender/blenlib/tests/BLI_string_ref_test.cc
M source/blender/functions/intern/field.cc
M source/blender/functions/intern/multi_function_builder.cc
M source/blender/functions/intern/multi_function_procedure_executor.cc
M source/blender/nodes/geometry/node_geometry_tree.cc
M source/blender/nodes/geometry/node_geometry_util.cc
M source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
M source/blender/nodes/geometry/nodes/node_geo_boolean.cc
M source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_distribute_points_in_volume.cc
M source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
M source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
M source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
M source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M source/blender/nodes/geometry/nodes/node_geo_input_material.cc
M source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
M source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
M source/blender/nodes/geometry/nodes/node_geo_interpolate_domain.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
M source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc
M source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
M source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
M source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
M source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
M source/blender/nodes/geometry/nodes/node_geo_switch.cc
M source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
M source/blender/nodes/geometry/nodes/node_geo_viewer.cc
M source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_allocator.hh b/source/blender/blenlib/BLI_allocator.hh
index f19292fffd8..149dda5a50e 100644
--- a/source/blender/blenlib/BLI_allocator.hh
+++ b/source/blender/blenlib/BLI_allocator.hh
@@ -65,13 +65,12 @@ class RawAllocator {
public:
void *allocate(size_t size, size_t alignment, const char *UNUSED(name))
{
- BLI_assert(is_power_of_2_i(static_cast<int>(alignment)));
+ BLI_assert(is_power_of_2_i(int(alignment)));
void *ptr = malloc(size + alignment + sizeof(MemHead));
void *used_ptr = reinterpret_cast<void *>(
- reinterpret_cast<uintptr_t>(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) &
- ~(static_cast<uintptr_t>(alignment) - 1));
- int offset = static_cast<int>((intptr_t)used_ptr - (intptr_t)ptr);
- BLI_assert(offset >= static_cast<int>(sizeof(MemHead)));
+ uintptr_t(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) & ~(uintptr_t(alignment) - 1));
+ int offset = int(intptr_t(used_ptr) - intptr_t(ptr));
+ BLI_assert(offset >= int(sizeof(MemHead)));
(static_cast<MemHead *>(used_ptr) - 1)->offset = offset;
return used_ptr;
}
diff --git a/source/blender/blenlib/BLI_any.hh b/source/blender/blenlib/BLI_any.hh
index f9b53436763..df67a090e92 100644
--- a/source/blender/blenlib/BLI_any.hh
+++ b/source/blender/blenlib/BLI_any.hh
@@ -42,12 +42,13 @@ template<typename ExtraInfo, typename T>
inline constexpr AnyTypeInfo<ExtraInfo> info_for_inline = {
is_trivially_copy_constructible_extended_v<T> ?
nullptr :
- +[](void *dst, const void *src) { new (dst) T(*(const T *)src); },
+ +[](void *dst, const void *src) { new (dst) T(*static_cast<const T *>(src)); },
is_trivially_move_constructible_extended_v<T> ?
nullptr :
- +[](void *dst, void *src) { new (dst) T(std::move(*(T *)src)); },
- is_trivially_destructible_extended_v<T> ? nullptr :
- +[](void *src) { std::destroy_at(((T *)src)); },
+ +[](void *dst, void *src) { new (dst) T(std::move(*static_cast<T *>(src))); },
+ is_trivially_destructible_extended_v<T> ?
+ nullptr :
+ +[](void *src) { std::destroy_at((static_cast<T *>(src))); },
nullptr,
ExtraInfo::template get<T>()};
diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh
index 813277d9968..200381048c9 100644
--- a/source/blender/blenlib/BLI_array.hh
+++ b/source/blender/blenlib/BLI_array.hh
@@ -424,8 +424,7 @@ class Array {
T *allocate(int64_t size)
{
- return static_cast<T *>(
- allocator_.allocate(static_cast<size_t>(size) * sizeof(T), alignof(T), AT));
+ return static_cast<T *>(allocator_.allocate(size_t(size) * sizeof(T), alignof(T), AT));
}
void deallocate_if_not_inline(T *ptr)
diff --git a/source/blender/blenlib/BLI_bit_vector.hh b/source/blender/blenlib/BLI_bit_vector.hh
index 2cec190f84a..ca6c6b2cd2a 100644
--- a/source/blender/blenlib/BLI_bit_vector.hh
+++ b/source/blender/blenlib/BLI_bit_vector.hh
@@ -106,7 +106,7 @@ class MutableBitRef {
MutableBitRef(uint8_t *byte_ptr, const int64_t bit_index)
{
byte_ptr_ = byte_ptr + (bit_index >> 3);
- mask_ = 1 << static_cast<uint8_t>(bit_index & 7);
+ mask_ = 1 << uint8_t(bit_index & 7);
}
/**
@@ -211,7 +211,7 @@ class BitVector {
data_ = inline_buffer_;
size_in_bits_ = 0;
capacity_in_bits_ = BitsInInlineBuffer;
- uninitialized_fill_n(data_, BytesInInlineBuffer, static_cast<uint8_t>(0));
+ uninitialized_fill_n(data_, BytesInInlineBuffer, uint8_t(0));
}
BitVector(NoExceptConstructor, Allocator allocator = {}) noexcept : BitVector(allocator)
@@ -447,7 +447,7 @@ class BitVector {
/* Fill entire bytes at once. */
const int64_t start_fill_byte_index = aligned_ranges.aligned.start() / BitsPerByte;
const int64_t bytes_to_fill = aligned_ranges.aligned.size() / BitsPerByte;
- const uint8_t fill_value = value ? (uint8_t)0xff : (uint8_t)0x00;
+ const uint8_t fill_value = value ? uint8_t(0xff) : uint8_t(0x00);
initialized_fill_n(data_ + start_fill_byte_index, bytes_to_fill, fill_value);
/* Fill bits in the end that don't cover a full byte. */
@@ -505,7 +505,7 @@ class BitVector {
* uninitialized byte. */
uninitialized_fill_n(new_data + bytes_to_copy,
new_capacity_in_bytes - bytes_to_copy,
- (uint8_t)initial_value_for_new_bytes);
+ uint8_t(initial_value_for_new_bytes));
if (!this->is_inline()) {
allocator_.deallocate(data_);
diff --git a/source/blender/blenlib/BLI_cpp_type_make.hh b/source/blender/blenlib/BLI_cpp_type_make.hh
index b0dbbff7ca8..3acef4b0f09 100644
--- a/source/blender/blenlib/BLI_cpp_type_make.hh
+++ b/source/blender/blenlib/BLI_cpp_type_make.hh
@@ -211,8 +211,8 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name)
using namespace cpp_type_util;
debug_name_ = debug_name;
- size_ = (int64_t)sizeof(T);
- alignment_ = (int64_t)alignof(T);
+ size_ = int64_t(sizeof(T));
+ alignment_ = int64_t(alignof(T));
is_trivial_ = std::is_trivial_v<T>;
is_trivially_destructible_ = std::is_trivially_destructible_v<T>;
if constexpr (std::is_default_constructible_v<T>) {
@@ -221,7 +221,7 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name)
value_initialize_ = value_initialize_cb<T>;
value_initialize_indices_ = value_initialize_indices_cb<T>;
static T default_value;
- default_value_ = (void *)&default_value;
+ default_value_ = &default_value;
}
if constexpr (std::is_destructible_v<T>) {
destruct_ = destruct_cb<T>;
diff --git a/source/blender/blenlib/BLI_function_ref.hh b/source/blender/blenlib/BLI_function_ref.hh
index 9a38176c988..bc386322c5d 100644
--- a/source/blender/blenlib/BLI_function_ref.hh
+++ b/source/blender/blenlib/BLI_function_ref.hh
@@ -116,7 +116,7 @@ template<typename Ret, typename... Params> class FunctionRef<Ret(Params...)> {
!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Callable>>, FunctionRef>))>
FunctionRef(Callable &&callable)
: callback_(callback_fn<typename std::remove_reference_t<Callable>>),
- callable_(reinterpret_cast<intptr_t>(&callable))
+ callable_(intptr_t(&callable))
{
}
diff --git a/source/blender/blenlib/BLI_generic_array.hh b/source/blender/blenlib/BLI_generic_array.hh
index 4b917434264..f0eddd30419 100644
--- a/source/blender/blenlib/BLI_generic_array.hh
+++ b/source/blender/blenlib/BLI_generic_array.hh
@@ -243,7 +243,7 @@ class GArray {
{
const int64_t item_size = type_->size();
const int64_t alignment = type_->alignment();
- return allocator_.allocate(static_cast<size_t>(size) * item_size, alignment, AT);
+ return allocator_.allocate(size_t(size) * item_size, alignment, AT);
}
void deallocate(void *ptr)
diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh b/source/blender/blenlib/BLI_generic_virtual_array.hh
index 21549896f45..9545eaf9622 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -315,7 +315,7 @@ template<typename T> class GVArrayImpl_For_VArray : public GVArrayImpl {
protected:
void get(const int64_t index, void *r_value) const override
{
- *(T *)r_value = varray_[index];
+ *static_cast<T *>(r_value) = varray_[index];
}
void get_to_uninitialized(const int64_t index, void *r_value) const override
@@ -325,22 +325,24 @@ template<typename T> class GVArrayImpl_For_VArray : public GVArrayImpl {
void materialize(const IndexMask mask, void *dst) const override
{
- varray_.materialize(mask, MutableSpan((T *)dst, mask.min_array_size()));
+ varray_.materialize(mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
}
void materialize_to_uninitialized(const IndexMask mask, void *dst) const override
{
- varray_.materialize_to_uninitialized(mask, MutableSpan((T *)dst, mask.min_array_size()));
+ varray_.materialize_to_uninitialized(
+ mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
}
void materialize_compressed(const IndexMask mask, void *dst) const override
{
- varray_.materialize_compressed(mask, MutableSpan((T *)dst, mask.size()));
+ varray_.materialize_compressed(mask, MutableSpan(static_cast<T *>(dst), mask.size()));
}
void materialize_compressed_to_uninitialized(const IndexMask mask, void *dst) const override
{
- varray_.materialize_compressed_to_uninitialized(mask, MutableSpan((T *)dst, mask.size()));
+ varray_.materialize_compressed_to_uninitialized(
+ mask, MutableSpan(static_cast<T *>(dst), mask.size()));
}
bool try_assign_VArray(void *varray) const override
@@ -422,7 +424,7 @@ template<typename T> class GVMutableArrayImpl_For_VMutableArray : public GVMutab
protected:
void get(const int64_t index, void *r_value) const override
{
- *(T *)r_value = varray_[index];
+ *static_cast<T *>(r_value) = varray_[index];
}
void get_to_uninitialized(const int64_t index, void *r_value) const override
@@ -443,40 +445,42 @@ template<typename T> class GVMutableArrayImpl_For_VMutableArray : public GVMutab
void set_by_relocate(const int64_t index, void *value) override
{
- T &value_ = *(T *)value;
+ T &value_ = *static_cast<T *>(value);
varray_.set(index, std::move(value_));
value_.~T();
}
void set_by_move(const int64_t index, void *value) override
{
- T &value_ = *(T *)value;
+ T &value_ = *static_cast<T *>(value);
varray_.set(index, std::move(value_));
}
void set_all(const void *src) override
{
- varray_.set_all(Span((T *)src, size_));
+ varray_.set_all(Span(static_cast<const T *>(src), size_));
}
void materialize(const IndexMask mask, void *dst) const override
{
- varray_.materialize(mask, MutableSpan((T *)dst, mask.min_array_size()));
+ varray_.materialize(mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
}
void materialize_to_uninitialized(const IndexMask mask, void *dst) const over
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list