Functions: make asserts more correct
It is valid to e.g. copy construct an integer in the same place, because it is a trivial type. It does not work for types like std::string. This fixes a crash reported in D12584 where it would copy a buffer into itself. We should probably also avoid doing this copy alltogether but that can be done separately.
This commit is contained in:
parent
2df7d1ebce
commit
3c1e75a230
|
@ -96,6 +96,7 @@ class CPPType : NonCopyable, NonMovable {
|
|||
int64_t size_ = 0;
|
||||
int64_t alignment_ = 0;
|
||||
uintptr_t alignment_mask_ = 0;
|
||||
bool is_trivial_ = false;
|
||||
bool is_trivially_destructible_ = false;
|
||||
bool has_special_member_functions_ = false;
|
||||
|
||||
|
@ -340,7 +341,6 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void copy_assign(const void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
@ -371,7 +371,7 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void copy_construct(const void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(src != dst || is_trivial_);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
@ -402,7 +402,6 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void move_assign(void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
@ -433,7 +432,7 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void move_construct(void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(src != dst || is_trivial_);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
@ -464,7 +463,7 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void relocate_assign(void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(src != dst || is_trivial_);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
@ -495,7 +494,7 @@ class CPPType : NonCopyable, NonMovable {
|
|||
*/
|
||||
void relocate_construct(void *src, void *dst) const
|
||||
{
|
||||
BLI_assert(src != dst);
|
||||
BLI_assert(src != dst || is_trivial_);
|
||||
BLI_assert(this->pointer_can_point_to_instance(src));
|
||||
BLI_assert(this->pointer_can_point_to_instance(dst));
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name)
|
|||
debug_name_ = debug_name;
|
||||
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>) {
|
||||
default_construct_ = default_construct_cb<T>;
|
||||
|
|
Loading…
Reference in New Issue