Sonic78
Sonic78

Reputation: 808

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

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?

Upvotes: 5

Views: 545

Answers (1)

T.C.
T.C.

Reputation: 137425

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.

Upvotes: 5

Related Questions