diff options
author | Matthias Hoelzl <tc@xantira.com> | 2017-11-18 08:46:53 +0100 |
---|---|---|
committer | Matthias Hoelzl <tc@xantira.com> | 2017-11-19 21:25:18 +0100 |
commit | 4c76c6892c1770f4e8f95bd8a4d8dcddf31d96d4 (patch) | |
tree | e9c0d3fabf688ce7a95241a9b45d8dfaa2ed2910 | |
parent | 63283eca5542314ea5b71afa1fe39bd48c202a4d (diff) |
Add placement deletes to avoid warnings on VC++
When compiling with VC++ 2017, Godot generates huge numbers of
C4291 warnings about missing placement delete.
I have not found a way to disable these warnings using compiler
options: AFAICT there is no equivalent to `-f-no-exceptions` for
VC++ (there is only /EH to change the exception-handling model,
/GX is deprecated) and adding /wd4291 to the
`disable_nonessential_warnings` list in the `SConstruct` file
or even compiling with `warnings=no` does not disable the
messages.
Placement delete is only called when placement new throws an
exception, since Godot doesn't use exceptions this change should
have no runtime effect.
Fixes #12654 (probably, difficult to say without log)
-rw-r--r-- | core/os/memory.cpp | 20 | ||||
-rw-r--r-- | core/os/memory.h | 8 |
2 files changed, 28 insertions, 0 deletions
diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 74d5cbbea1..439951f711 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -44,6 +44,26 @@ void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) { return p_allocfunc(p_size); } +#ifdef _MSC_VER +void operator delete(void *p_mem, const char *p_description) { + + ERR_EXPLAINC("Call to placement delete should not happen."); + CRASH_NOW(); +} + +void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) { + + ERR_EXPLAINC("Call to placement delete should not happen."); + CRASH_NOW(); +} + +void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description) { + + ERR_EXPLAINC("Call to placement delete should not happen."); + CRASH_NOW(); +} +#endif + #ifdef DEBUG_ENABLED uint64_t Memory::mem_usage = 0; uint64_t Memory::max_usage = 0; diff --git a/core/os/memory.h b/core/os/memory.h index f8b3da579b..7801d56837 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -72,6 +72,14 @@ void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< ope void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory +#ifdef _MSC_VER +// When compiling with VC++ 2017, the above declarations of placement new generate many irrelevant warnings (C4291). +// The purpose of the following definitions is to muffle these warnings, not to provide a usable implementation of placement delete. +void operator delete(void *p_mem, const char *p_description); +void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)); +void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description); +#endif + #define memalloc(m_size) Memory::alloc_static(m_size) #define memrealloc(m_mem, m_size) Memory::realloc_static(m_mem, m_size) #define memfree(m_size) Memory::free_static(m_size) |