Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are STL container elements explicitly required to be (noexcept) destructible?

Tags:

c++

c++11

stl

C++11 (and C++14) STL containers have noexcept destructors and clear() member functions.

This implies that the elements should have noexcept destructors too, or at least that the actual elements stored in containers should not throw any exceptions when destroyed—or more correctly, that the corresponding allocator_traits<Allocator>::destroy call should not throw.

Is this specified as a requirement (explicitly or implied by another explicit requirement) anywhere in the standard? If not, why?

I know is_nothrow_constructible requires a noexcept destructor, but is_constructible alone doesn’t, and container requirements are specified in terms of concepts rather than type traits templates anyway.

like image 405
Chortos-2 Avatar asked Mar 27 '15 15:03

Chortos-2


1 Answers

17.6.4.8/1 In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.

17.6.4.8/2 In particular, the effects are undefined in the following cases:

...

  • if any replacement function or handler function or destructor operation exits via an exception, unless specifically allowed in the applicable Required behavior: paragraph.
like image 158
Igor Tandetnik Avatar answered Sep 30 '22 00:09

Igor Tandetnik