c++ - replacing new with macro conflicts with placement new -
i've got massive application (several million loc, , tens of thousands of files), , i'm trying use debug crt detect memory leaks. i'm trying macro-ize new so:
#define _crtdbg_map_alloc #include <crtdbg.h> #ifndef new_debug #define new_debug new(_normal_block, __file__, __line__) #define new new_debug #endif
now, app big, me, ideally, put in header file , include in tens of thousands of cpp files. not fun task. i've attempted place in common header file in our sdk, included in every translational unit.
the problem i'm running seems clash stl header files, , compiler emits errors when placement new used. can change in own code, using pragma's , disabling new macro. not problem there. it's stl header files use placement new, can't change.
i've figured out work-around, rearranging include directives in cpp files. example:
// doesn't compile #include "new_redirect.h" #include <map> // instance // compile #include <map> // instance #include "new_redirect.h"
but difficult work-around because again, have go modify thousands of files, , make sure stl headers included before else. ironic thing, created hello world application test problem: , hello-world app of mine compiled fine. massive app doesn't, without work-around.
so questions are:
- has been able macro-ize new without jiggling massive amounts of code? (in relatively painless way)
- any other way around re-arranging stl header include directives?
thanks
you can catch placement new variadic macro:
#define new_debug(...) new_debug2(_normal_block, __file__, __line__, __va_args__ ) #define new new_debug
but preprocessor doesn't seem allow defining macro both arguments , without, , macro without arguments applied first, didn't find way single preprocessor pass. seems possible two, if we'd run first pass above macros , /e, second pass with
#define new_debug new(_normal_block, __file__, __line__) #define new_debug2(...) new(__va_args__ )
Comments
Post a Comment