在下面的代码中,我认为断言不应该触发,但它确实触发了。
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/