noexcept, stack unwinding and performance

后端 未结 4 1553
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 09:47

The following draft from Scott Meyers new C++11 book says(page 2, lines 7-21)

The difference between unwinding the call stack and possibly unwinding i

4条回答
  •  长情又很酷
    2020-12-08 10:14

    The difference between noexcept and throw() is that in case of throw() the exception stack is still unwound and destructors are called, so implementation has to keep track of the stack (see 15.5.2 The std::unexpected() function in the standard).

    On the contrary, std::terminate() does not require the stack to be unwound (15.5.1 states that it is implementation-defined whether or not the stack is unwound before std::terminate() is called).

    GCC seem to really not unwind the stack for noexcept: Demo
    While clang still unwinds: Demo

    (You can comment f_noexcept() and uncomment f_emptythrow() in the demos to see that for throw() both GCC and clang unwind the stack)

提交回复
热议问题