C ++ standard section id, which states that destructors do not implicitly throw

I read somewhere that with C ++ 11, destructors are declared implicitly noexcept(true) .

From standard section 12.4

A destructor declaration that does not have an exception specification has the same exception specification, as if it had implicitly declared

But nowhere in the standard could I find a section where it says that destructors are implicitly noexcept(true) . Can someone point me to a section where I can find this information?

+6
source share
2 answers

I believe that you are looking for Β§15.4 / 14 (my attention):

The following constructor (12.9) and the implicitly declared special member function (section 12) have Exception specifications. If f is a successor constructor or an implicitly declared default constructor, copy the constructor, move constructor, destructor , copy assignment operator, or redirect operator, its implicit exception-specification indicates an identifier of type T if and only if T allowed by the exception specification of the function directly called implicit definition of f s; f allows all exceptions if any function directly invokes allows all exceptions, and f has an exception specification noexcept (true) if each function directly invokes does not allow exceptions. [Note: It follows that f has an exception specification noexcept(true) if it does not call any other functions . -end note]

+3
source

A description of how a special specification for the exclusion of an implicit element is generated is given in 15.4 / 14. This is not very clear, but it is basically said that the special member only gives those exceptions that the special members of the grounds and the members that he causes throw; this means that a) if there are no grounds or members, there will be no exceptions, and b) if all bases and members do not generate exceptions, there will be no exceptions. The end result is that the destructors are noexcept(true) if there is no element or base destructor.

+3
source

Source: https://habr.com/ru/post/981275/


All Articles