From 4463087223983c40a6d67beab0513fba7cdb7538 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 16 Dec 2020 15:59:58 +0100 Subject: BLI: remove implicit casts between some span types Casting pointers from one type to another does change the value of the pointer in some cases. Therefore, casting a span that contains pointers of one type to a span that contains pointers of another type, is not generally safe. In practice, this issue mainly comes up when dealing with classes that have a vtable. There are some special cases that are still allowed. For example, adding const to the pointer does not change the address. Also, casting to a void pointer is fine. In cases where implicit conversion is disabled, but one is sure that the cast is valid, an explicit call of `span.cast()` can be used. --- source/blender/blenlib/tests/BLI_memory_utils_test.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender/blenlib/tests/BLI_memory_utils_test.cc') diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index fcef2f8688a..23415e69b04 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -158,4 +158,15 @@ static_assert(is_convertible_pointer_v); static_assert(is_convertible_pointer_v); static_assert(is_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(!is_span_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(!is_span_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(is_span_convertible_pointer_v); +static_assert(!is_span_convertible_pointer_v); +static_assert(!is_span_convertible_pointer_v); + } // namespace blender::tests -- cgit v1.2.3