其他分享
首页 > 其他分享> > noexcept函数是否仍然可以调用C 17中的函数?

noexcept函数是否仍然可以调用C 17中的函数?

作者:互联网

P0012R1中,“使异常规范成为类型系统的一部分”,
我看到noexcept现在正成为函数类型的一部分.

我不知道这是否会阻止noexcept(true)函数仍能调用noexcept(false)函数.

以下代码是否仍然适用于C 17?

void will_throw() noexcept(false){
  throw 0;
}

void will_not_throw() noexcept(true){
  will_throw();
}

解决方法:

根据cppreference

Note that a noexcept specification on a function is not a compile-time
check; it is merely a method for a programmer to inform the compiler
whether or not a function should throw exceptions.

因此,代码的语法有效,但执行时将调用std::terminate.

标签:noexcept,c,exception,function-pointers,c17
来源: https://codeday.me/bug/20191002/1841199.html