Hacker News new | ask | show | jobs
by nextaccountic 681 days ago
Oh, so it's like Rust's panic=abort
1 comments

Panic=abort is more like -fno-exceptions since it applies to all the code being compiled and not just function. Codegen can also take advantage of the fact that it won't have to unwind.

I don't think there is a rust equivalent of noexcept.

Does C++ std::terminate unwind the stack and call destructors? Then noexcept would be pretty close to regular Rust panics, wouldn't it?

Basically an unrecoverable exception?

The behavior of `-fno-exceptions` isn't standardized, because it's a compiler feature, not a part of the C++ standard. The standard says:

> In the situation where no matching [exception] handler is found, it is implementation-defined whether or not the stack is unwound before std::terminate is invoked. In the situation where the search for a handler encounters the outermost block of a function with a non-throwing exception specification, it is implementation-defined whether the stack is unwound, unwound partially, or not unwound at all before the function std::terminate is invoked.

So, the whole thing is basically implementation-defined (including `-fno-exceptions`, since that is something that implementing compilers provide).

> Does C++ std::terminate unwind the stack and call destructors?

No, it doesn't. Try this: https://godbolt.org/z/cvG17cYEs