https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102882
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to David Edelsohn from comment #0) > Does this testcase require overriding operator new[] in the library itself, > not only the testcase? Yes, I think so. The allocations done by the std::string objects will be done by the explicit instantiations of std::string inside the library. Maybe the real solution is to stop explicitly instantiating class templates in the library. If std::string was instantiated in the tests then all the allocations would be done in the tests, and the 'operator new' replacement would work. That seems like it would remove a whole class of problems where the allocations and deallocations might happen in different binary objects. The downside would be slower compilation, because every object file would re-instantiate the same templates. Avoiding that cost is the purpose of the explicit instantiations, but if they cause incorrect behaviour, maybe the cost is worth it.