From 718d4ffe9fb3d63c1d42517181dc016f92e5d8df Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 21 Feb 2025 10:30:29 +0100 Subject: [PATCH] Add some type-check to `MEM_freeN` with MSVC. Using `DNA_DEFINE_CXX_METHODS` in DNA structs make them non-trivially copyable for MSVC, so use a narrower check that should still catch most issues. Pull Request: https://projects.blender.org/blender/blender/pulls/134875 --- intern/guardedalloc/MEM_guardedalloc.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 79f8a311185..92e8fe17032 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -399,11 +399,14 @@ template inline T *MEM_cnew(const char *allocation_name, const T &ot template inline void MEM_freeN(T *ptr) { -# ifndef _MSC_VER +# ifdef _MSC_VER /* MSVC seems to consider C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial. GCC * and clang (both on linux, OSX and clang-cl on Windows on Arm) do not. * * So for now, disable the triviality check on MSVC. */ + static_assert(std::is_trivially_destructible_v, + "For non-trivial types, MEM_delete must be used."); +# else static_assert(std::is_trivial_v, "For non-trivial types, MEM_delete must be used."); # endif mem_guarded::internal::mem_freeN_ex(const_cast(static_cast(ptr)),