When I look at the Container
requirements on cppreference it lists Destructible
as a requirement for value_type
. This seems to imply that destructors of container elements may not throw.
I haven't been able to find a citation for this requirement in the C++14 standard (haven't looked in older versions). The only thing I can find is that value_type
must be Erasable
which doesn't imply any exception safety at all.
So my question is, may the elements in a std::vector
have a throwing destructor? If not, what section in the standard prohibits it?
P.S.: Don't worry, I'm not planning to create types with throwing destructors. I'm just writing a standard-conforming implementation and trying to get exception safety right.
N4140 [res.on.functions]/2 states:
Which is a bit obscure, but saves a lot of space that would otherwise be wasted on "
T
must meet the Destructible requirements" statements throughout the library clauses.Notably, this does not imply that elements of a
std::vector
can't have a throwing destructor; it only means that said destructor must never throw when called from the standard library. So e.g. this program is conforming: