Search code examples
c++visual-studio-2010visual-c++-2010

VS2008 to VS 2010 migration - a breaking change?


I encountered a problem when migrating our C++ code from VS2008 to VS2010. I can't find an explanation for the reason of it so far and will appreciate your help.

We have a custom memory allocator and it resides in a dll. In the rest of the code we use the preprocessor to redirect the allocations to our functions. Thie following simple code compiles correctly in VS2008, but does not in VS2010.

in stdafh.h:

#define free my_free
#include <string>

In VS2010 I get:

1>d:\program files\microsoft visual studio 10.0\vc\include\xdebug(62): error C3861: 'free': identifier not found

Coming from the line:

template<class _Ty>
    void __CLRCALL_OR_CDECL _DebugHeapDelete(_Ty *_Ptr)
    {   // delete from the debug CRT heap even if operator delete exists
    if (_Ptr != 0)
        {   // worth deleting
        _Ptr->~_Ty();
        // delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
        // facets allocated by normal new.
        free(_Ptr);

Any help or ideas will be highly appreciated!

Moshe


Solution

  • After some investigation using the /P option to create the preprocessor files and studying them I've found the root cause of the issue.

    The xdebug header, which describes itself as "debug heap support header for Microsoft", contains the following lines:

    #pragma push_macro("free")
    #undef free
    

    which obviously defeat our attempts to redefine it. So this is not something new to the compiler, just plain #undef that happens to occur with the functions we try to redefine