I read somewhere that since c++11, the destructors are implicitly declared noexcept(true)
.
From the standard section 12.4
A declaration of a destructor that does not have an exception-specification has the same exception specification as if had been implicitly declared
But nowhere in the standard could I find a section where in it says that destructors are implicitly noexcept(true)
. Can anyone point me to the section where I can find this information?
I believe you are looking for §15.4/14 (emphasis mine):
An inheriting constructor (12.9) and an implicitly declared special member function (Clause 12) have an exception-specification. If
f
is an inheriting constructor or an implicitly declared default constructor, copy constructor, move constructor, destructor, copy assignment operator, or move assignment operator, its implicit exception-specification specifies the type-idT
if and only ifT
is allowed by the exception-specification of a function directly invoked byf
’s implicit definition;f
allows all exceptions if any function it directly invokes allows all exceptions, and f has the exception-specification noexcept(true) if every function it directly invokes allows no exceptions. [ Note: It follows thatf
has the exception-specificationnoexcept(true)
if it invokes no other functions. —end note ]
The description of how a special member's implicit exception specification is formed is in 15.4/14. It's not very clear, but it basically says that a special member only throws those exceptions thrown by the special members of the bases and members it calls; this implies that a) if there are no bases or members, there won't be any exceptions, and b) if all bases and members don't throw exceptions, there won't be any exceptions. The end result is that destructors are noexcept(true)
unless any member or base's destructor is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With