lundi 6 mars 2017

C++ operator new overloading, compilation error

When I overload new operator globally to track mem leaks, I get compilation error in the following place

 ::new(__tmp) _Rb_tree_node<_Val>;

looks like they allocate and fill the node there. Following is the error:

/home/symbol/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/functional: In static member function 'static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::true_type)':/home/symbol/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/functional:1870:9: error: '__dest' does not name a type
new (__dest._M_access()) _Functor(__source._M_access<_Functor>());

Below is my overloading code:

void* operator new(std::size_t sz,char const* file, int line){  
return newImpl(sz,file,line);
}

void* operator new [](std::size_t sz,char const* file, int line){  
return newImpl(sz,file,line);
}

void operator delete(void* ptr) noexcept{
auto ind=std::distance(myAlloc.begin(),std::find(myAlloc.begin(),myAlloc.end(),ptr)    );
myAlloc[ind]= nullptr;
free(ptr);
}

#define new new(__FILE__, __LINE__)

Aucun commentaire:

Enregistrer un commentaire