c++ - noexcept 一个函数返回一个具有抛出析构函数的类

标签 c++ c++11 noexcept

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

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

关于c++ - noexcept 一个函数返回一个具有抛出析构函数的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128009/

相关文章:

c++ - noexcept 运算符编译时检查

c++ - 使用c++调用和使用Windows语音识别

c++ - SFML 不会在 CodeBlocks 13.12 中运行

c++ - VS2015 C++ : unable to match function definition to an existing declaration

c++ - L 和 R 引用变量

c++ - 对数组 : can it actually happen? 的右值引用

c++ - 类型特征 `is_noexcept` 、 `add_noexcept` 和 `remove_noexcept` ?

c++ - 为什么我默认的移动构造函数不是 noexcept?

c++ - 将递归更改为更便宜的东西

c++ - 关于智能指针,VS2010 和 VS2012 中的内存头之间的区别在哪里?