std - C++ default allocator - what should happen if the size doesn't equal the size passed to the invocation of allocate? -
20.6.9:
void deallocate(pointer p, size_type n);
- requires: p shall pointer value obtained allocate(). n shall equal value passed first argument invocation of allocate returned p.
- effects: deallocates storage referenced p.
- remarks: uses ::operator delete(void*) (18.6.1), unspecified when function called.
what should happen if n
doesn't equal value passed first agrgument invocation of allocate returned p
? not deallocate? throw std::bad_alloc
? ...
edit: meant "what should happen" was: okay throw or assert in custom implementation?
as usual in c++ standard, when nothing stated explicitly, violating requirements leads undefined behavior. shall means at times must, it's requirement, not option in c++ standard.
for example here's msdn says:
the pointer _ptr must have been returned earlier call allocate allocator object compares equal *this, allocating array object of same size , type.
which means size must match precisely, otherwise run undefined behavior.
Comments
Post a Comment