Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ standard section id where its mentioned that Destructors are implicitly no throw

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?

like image 684
Arun Avatar asked Jan 20 '15 13:01

Arun


2 Answers

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-id T if and only if T is allowed by the exception-specification of a function directly invoked by f’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 that f has the exception-specification noexcept(true) if it invokes no other functions. —end note ]

like image 154
Barry Avatar answered Oct 12 '22 19:10

Barry


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.

like image 37
Sebastian Redl Avatar answered Oct 12 '22 20:10

Sebastian Redl