First of all, I don’t think it is. But, I’ve observed such a behavior with MSVC 10.0 in Debug mode. I’m using a custom allocator class which relies on the user to pass only pointers allocated on the same instance to deallocate. However, in Release mode, my code is working.
Is this a bug or am I mistaken?
The standard requires that any allocator be able to deallocate memory produced by any other allocator of the same type, even if it’s a totally different instance. This is required to get
list::spliceworking correctly. It’s largely considered a design flaw in the C++ spec, and in C++0x they’re introducing a set of fixups to allocators to rememdy this. In the meantime, any allocator you use in the STL containers must not have its own local state.EDIT: For those of you who want the original language on this, here’s §20.1.5/4 of the C++ ISO spec:
In the latest ISO draft of the C++0x standard, this requirement is no longer present. The default
std::allocatorwill still maintain this invariant as required, but it doesn’t look like you’ll have to constrain yourself this way in the future.