From 1107af1abb0d4bf271e995a18f5d4bd790d51d02 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 26 Jan 2020 16:38:18 +0100 Subject: Fix OBJECT_GUARDED_FREE compiler error when type is in namespace --- intern/guardedalloc/MEM_guardedalloc.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'intern') diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index b1a0eda0e22..958e5ae86cd 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -230,6 +230,10 @@ extern const char *(*MEM_name_ptr)(void *vmemh); /* Switch allocator to slower but fully guarded mode. */ void MEM_use_guarded_allocator(void); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #ifdef __cplusplus /* alloc funcs for C++ only */ # define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \ @@ -253,6 +257,13 @@ void MEM_use_guarded_allocator(void); MEM_freeN(mem); \ } +/* Needed when type includes a namespace, then the namespace should not be + * specified after ~, so using a macro fails. */ +template inline void OBJECT_GUARDED_DESTRUCTOR(T *what) +{ + what->~T(); +} + # if defined __GNUC__ # define OBJECT_GUARDED_NEW(type, args...) new (MEM_mallocN(sizeof(type), __func__)) type(args) # else @@ -262,15 +273,11 @@ void MEM_use_guarded_allocator(void); # define OBJECT_GUARDED_DELETE(what, type) \ { \ if (what) { \ - ((type *)(what))->~type(); \ + OBJECT_GUARDED_DESTRUCTOR((type *)what); \ MEM_freeN(what); \ } \ } \ (void)0 #endif /* __cplusplus */ -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* __MEM_GUARDEDALLOC_H__ */ -- cgit v1.2.3