Header file:
#if defined(_DEBUG) #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> extern __declspec(thread) char const * t_File; extern __declspec(thread) int t_Line; inline void * __CRTDECL operator new (size_t const size) { return ::operator new (size, _NORMAL_BLOCK, t_File, t_Line); } inline void * __CRTDECL operator new[](size_t const size) { return ::operator new[](size, _NORMAL_BLOCK, t_File, t_Line); } #define new (t_File = __FILE__, t_Line = __LINE__, false) ? nullptr : new #endifSource file:
#if defined(_DEBUG) __declspec(thread) char const * t_File = "???"; __declspec(thread) int t_Line = 0; #endif
This macro doesn't work with direct operator call like operator new(...) in code.
P.S. This macro tested only on Visual Studio 2012