NetBurner 3.1
MemoryLeakDetectorNewMacros.h
1 
2 /*
3  * This file can be used to get extra debugging information about memory leaks in your production code.
4  * It defines a preprocessor macro for operator new. This will pass additional information to the
5  * operator new and this will give the line/file information of the memory leaks in your code.
6  *
7  * You can use this by including this file to all your production code. When using gcc, you can use
8  * the -include file to do this for you.
9  *
10  * Warning: Using the new macro can cause a conflict with newly declared operator news. This can be
11  * resolved by:
12  * 1. #undef operator new before including this file
13  * 2. Including the files that override operator new before this file.
14  * This can be done by creating your own NewMacros.h file that includes your operator new overrides
15  * and THEN this file.
16  *
17  * STL (or StdC++ lib) also does overrides for operator new. Therefore, you'd need to include the STL
18  * files *before* this file too.
19  *
20  */
21 
22 #include "CppUTestConfig.h"
23 
24 /* Make sure that mem leak detection is on and that this is being included from a C++ file */
25 #if CPPUTEST_USE_MEM_LEAK_DETECTION && defined(__cplusplus)
26 
27 /* This #ifndef prevents <new> from being included twice and enables the file to be included anywhere */
28 #ifndef CPPUTEST_USE_NEW_MACROS
29 
30  #if CPPUTEST_USE_STD_CPP_LIB
31  #include <new>
32  #include <memory>
33  #include <string>
34  #endif
35 
36  void* operator new(size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
37  void* operator new[](size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
38  void* operator new(size_t size) UT_THROW(std::bad_alloc);
39  void* operator new[](size_t size) UT_THROW(std::bad_alloc);
40 
41  void operator delete(void* mem, const char* file, int line) UT_NOTHROW;
42  void operator delete[](void* mem, const char* file, int line) UT_NOTHROW;
43  void operator delete(void* mem) UT_NOTHROW;
44  void operator delete[](void* mem) UT_NOTHROW;
45  void operator delete (void* mem, size_t size) UT_NOTHROW;
46  void operator delete[] (void* mem, size_t size) UT_NOTHROW;
47 
48 #endif
49 
50 
51 #ifdef __clang__
52  #pragma clang diagnostic push
53  #if __clang_major__ >= 3 && __clang_minor__ >= 6
54  #pragma clang diagnostic ignored "-Wkeyword-macro"
55  #endif
56 #endif
57 
58 #define new new(__FILE__, __LINE__)
59 
60 #ifdef __clang__
61  #pragma clang diagnostic pop
62 #endif
63 
64 #define CPPUTEST_USE_NEW_MACROS 1
65 
66 #endif