noexcept 函数返回一个 class 并抛出析构函数

noexcept of a function returning a class having throwing destructor

在下面的代码中,我认为断言不应该触发,但它确实触发了。

struct A
{
  ~A() noexcept(false);
};

A f() noexcept;

int main()
{
  static_assert(noexcept(f()), "f must be noexcept");
}

函数f()显然是noexcept,但是noexcept(f())被计算为false。 (在 gcc 和 clang 中)

我是不是遗漏了什么或者是错误?

表达式 e 上的 noexcept 运算符告诉您表达式的 潜在异常集 是否为空。该集合包含析构函数的潜在异常,根据 [except.spec]/(13.2):

If e implicitly invokes one or more functions (such as an overloaded operator, an allocation function in a new-expression, or a destructor if e is a full-expression (1.9)), S is the union of: [...] the sets of types in the exception specifications of all such functions