cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

C++23's `unreachable()`

Open lefticus opened this issue 3 years ago • 1 comments

https://en.cppreference.com/w/cpp/utility/unreachable

lefticus avatar Jul 23 '22 14:07 lefticus

And how does it compare to things we might be currently using like assert(false);, abort(), exit(), etc.

reedhedges avatar Aug 26 '22 18:08 reedhedges

https://compiler-explorer.com/z/13Y87Y3ev

lefticus avatar May 13 '23 23:05 lefticus

Thanks, played around with that a bit. One thing to be aware of is that std::unreachable() really needs to be unreachable I think?. If you make some mistake and it's not then you get fun ub? https://compiler-explorer.com/z/odahGYnTe

reedhedges avatar May 15 '23 14:05 reedhedges

Thanks, played around with that a bit. One thing to be aware of is that std::unreachable() really needs to be unreachable I think?. If you make some mistake and it's not then you get fun ub? https://compiler-explorer.com/z/odahGYnTe

It's explicitly defined as invoking UB, in fact. It feels dangerous to me.

lefticus avatar May 17 '23 19:05 lefticus

Coming in episode 393

lefticus avatar Jul 27 '23 17:07 lefticus