Why is std::allocator::deallocate not noexcept?

Viewed 425

The C++ specification (ISO/IEC 14882:2011 + ISO/IEC 14882:2014) defines in Table 28 — Allocator requirements for deallocate:

All n T objects in the area pointed to by p shall be destroyed prior to this call. n shall match the value passed to allocate to obtain this memory. Does not throw exceptions.

But why is deallocate still not noexcept?

1 Answers

It's narrow contract (causing undefined behavior if you pass it a pointer not returned by allocate, for instance), so per the standard library's usual policy it's not marked noexcept.

Related