From 4126284e461a059a6063efe1d11c1edfa3d5c60d Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 14 Feb 2023 12:38:18 +0100 Subject: [PATCH] Allocator: Fail building when trying to MEM_delete a void pointer `MEM_delete()` is designed for type safe destruction and freeing, void pointers make that impossible. Was reviewing a patch that was trying to free a C-style custom data pointer this way. Apparently MSVC compiles this just fine, other compilers error out. Make sure this is a build error on all platforms with a useful message. --- intern/guardedalloc/MEM_guardedalloc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 5ae33343949..69221877f15 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -281,6 +281,8 @@ inline T *MEM_new(const char *allocation_name, Args &&...args) */ template inline void MEM_delete(const T *ptr) { + static_assert(!std::is_void_v, + "MEM_delete on a void pointer not possible. Cast it to a non-void type?"); if (ptr == nullptr) { /* Support #ptr being null, because C++ `delete` supports that as well. */ return;