From e31b0c1803d976e29b258c7307e32fd0d63821e5 Mon Sep 17 00:00:00 2001 From: Yasha Jannoo Date: Thu, 12 Sep 2019 00:41:34 +0100 Subject: Fix ill-formed and warning-causing new overloaded and delete operators From VS2015 onwards, overloaded new and delete operators were no longer allowed to be declared inline. See https://docs.microsoft.com/en-us/cpp/porting/visual-cpp-what-s-new-2003-through-2015?view=vs-2019. As a consequence of moving the definitions into source files, we cannot simply include the headers in the files they are required in without also either creating a static library or including the source files in the projects. Do the latter as the pattern fits other examples of dependencies across projects in the solution. The overloaded operator definitions could be made neater in a future change. For now they are written as their declarations appear in the header file, with the same ifdefs as in the header file. --- FoundationEx/MemDebug.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++ FoundationEx/MemDebug.h | 17 +++++-------- 2 files changed, 72 insertions(+), 10 deletions(-) (limited to 'FoundationEx') diff --git a/FoundationEx/MemDebug.cpp b/FoundationEx/MemDebug.cpp index 2694b33..4f3174f 100644 --- a/FoundationEx/MemDebug.cpp +++ b/FoundationEx/MemDebug.cpp @@ -45,7 +45,9 @@ // +--------------------------------------------------------------------+ +#ifndef FOUNDATION_USE_MFC static Memory::LEVEL mem_chk_level = Memory::PERIODIC; +#endif #ifdef _DEBUG static _CrtMemState mem_chk_p1, @@ -61,6 +63,66 @@ static HANDLE mem_log_file = 0; #define CrtClrDebugField(a) _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)) #endif +#ifdef FOUNDATION_USE_MFC + +#ifndef _DEBUG + +void* __cdecl operator new(unsigned int s, const char*, int) +{ + return ::operator new(s); +} + +void __cdecl operator delete(void* p, const char*, int) +{ + ::operator delete(p); +} + +#else + +// No definitions for the following: +//void* __cdecl operator new(unsigned int s, const char*, int) {} +//void __cdecl operator delete(void* p, const char*, int) {} + +#endif + +#else // if not defined FOUNDATION_USE_MFC + +#ifndef _DEBUG + +void* __cdecl operator new(unsigned int s, const char*, int) +{ + return ::operator new(s); +} + +void __cdecl operator delete(void* p, const char*, int) +{ + ::operator delete(p); +} + +#else + +// No definitions for the following: +//void* __cdecl operator new(unsigned int, int, const char*, int) {} + +void* __cdecl operator new(unsigned int s, const char* f, int l) +{ + return ::operator new(s, 1, f, l); +} + +void* __cdecl operator new(unsigned int s) +{ + return ::operator new(s, 1, __FILE__, __LINE__); +} + +void __cdecl operator delete(void* p, const char*, int) +{ + ::operator delete(p); +} + +#endif _DEBUG + +#endif FOUNDATION_USE_MFC + static void heapdump() { _HEAPINFO hinfo; @@ -107,6 +169,7 @@ static void heapdump() // +--------------------------------------------------------------------+ +#ifndef FOUNDATION_USE_MFC void Memory::OpenLog(const char* filename) { @@ -234,3 +297,5 @@ Memory::SetLevel(LEVEL l) #endif } +#endif + diff --git a/FoundationEx/MemDebug.h b/FoundationEx/MemDebug.h index 14bc0cf..0bd63da 100644 --- a/FoundationEx/MemDebug.h +++ b/FoundationEx/MemDebug.h @@ -51,8 +51,8 @@ #ifndef _DEBUG -inline void* __cdecl operator new(unsigned int s, const char*, int) { return ::operator new(s); } -inline void __cdecl operator delete(void* p, const char*, int) { ::operator delete(p); } +void* __cdecl operator new(unsigned int s, const char*, int); +void __cdecl operator delete(void* p, const char*, int); #else @@ -89,21 +89,18 @@ public: #ifndef _DEBUG -inline void* __cdecl operator new(unsigned int s, const char*, int) { return ::operator new(s); } -inline void __cdecl operator delete(void* p, const char*, int) { ::operator delete(p); } +void* __cdecl operator new(unsigned int s, const char*, int); +void __cdecl operator delete(void* p, const char*, int); #else /*_CRTIMP*/ void* __cdecl operator new(unsigned int, int, const char*, int); -inline void* __cdecl operator new(unsigned int s, const char* f, int l) - { return ::operator new(s, 1, f, l); } +void* __cdecl operator new(unsigned int s, const char* f, int l); -inline void* __cdecl operator new(unsigned int s) - { return ::operator new(s, 1, __FILE__, __LINE__); } +void* __cdecl operator new(unsigned int s); -inline void __cdecl operator delete(void* p, const char*, int) - { ::operator delete(p); } +void __cdecl operator delete(void* p, const char*, int); #endif _DEBUG -- cgit v1.1