在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
执行时会被调用。
关于c++ - noexcept 函数仍然可以调用在 C++17 中抛出的函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39763401/