20.6.9:
void deallocate(pointer p, size_type n);
What should happen if n
doesn't equal the value passed as the first agrgument to the invocation of allocate which returned p
? Not deallocate? Throw std::bad_alloc
? ...
EDIT: What I actually meant with "what should happen" was: Would it be okay to throw or assert in a custom implementation?
As usual in C++ Standard, when nothing is stated explicitly, violating the requirements leads to undefined behavior. Shall means at all times must, it's a requirement, not an option in C++ Standard.
For example here's what MSDN says:
The pointer _Ptr must have been returned earlier by a call to allocate for an allocator object that compares equal to *this, allocating an array object of the same size and type.
which means that the size must match precisely, otherwise you run into undefined behavior.
It doesn't say. Which means that it would be the nasty "undefined behviour".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With