Is it guaranteed that C++ standard library containers call the replaceable new functions?

c++, c++11, language-lawyer

Solution

The default allocator for allocator-aware containers such as `std::vector<T>` is `std::allocator<T>`. This class template is described in section [default.allocator] of the standard. According to [allocator.members]/6 in C++14:

the storage is obtained by calling `::operator new(std::size_t)`

So the global operator new is the one that you need to replace. If you overloaded `operator new` specifically for `T`, that overload will not be used by the default allocator.

Problem

If I replace all the `operator new` signatures that I can, at least on the implementations I have tested, I see that the standard containers call into my replaced versions to allocate memory. Is this guaranteed by the standard? That is, would it be illegal for an implementation to use an optimized version which didn't call my replacement functions for the memory underlying the standard containers?

Original source