I've faced with problem which was caused by conjunction of overloaded operators new/delete and STL (especially std::string). Here's my case...
I compile shared library (call it libfoo.so), in which I overload operators new and delete. In order to not impact program which will use this library, I made symbols new and delete hidden.Also my library uses STL, especially std::string, which as I expect should use my operators new/delete since it is template class.
When I compile library with -O1 and above I get SIGABRT which was cause by using different operators new/delete in basic_string constructor/destructor. new is called from libstdc++.so but delete is called from my library.
When I compile library with -O0 or -fno-inline operators new/delete for basic_string constructor/destructor are both called from libstdc++.
I made minimal example which show such behavior: https://github.com/yekatkov/CustomNewDelete
Steps for reproducing of error are in Readme.md.
Is it normal behavior of optimization? Or may be I should use std::string in different way? How to force stl classes in my library to use my new/delete? Suppose my real library has tons of stl classes, hence I can't redefine allocator for each of them. :(
I use glibc 2.27, gcc 5.5.0
Be glad to listen any ideas :)
Thanks!