c ++标准部分ID,其中提到析构函数隐含地没有抛出

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

我在某处读到,自 c++11 起,析构函数被隐式声明 noexcept(true)

来自标准第 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

但是在标准中的任何地方我都找不到一个部分说析构函数是隐式的noexcept(true)。谁能指出我可以找到此信息的部分?

我相信您正在寻找 §15.4/14(强调我的):

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 ]

关于特殊成员的隐式异常规范是如何形成的描述在15.4/14。不是很清楚,但是基本上是说一个特殊成员only抛出那些base的特殊成员和它调用的成员抛出的那些异常;这意味着 a) 如果没有基或成员,则不会有任何异常,并且 b) 如果所有基和成员都不抛出异常,则不会有任何异常。最终结果是析构函数是 noexcept(true) 除非任何成员或基的析构函数不是。