5 ms·
Shoot I have done that in the past but it seems I actually wanted __builtin_trap().
by jstimpfle 6y ago
Shoot I have done that in the past but it seems I actually wanted __builtin_trap().
- kevincox 6y agoYeah, that footgun should really have a more explicit name. __dear_compiler_i_promise_that_this_statement_is_unreachable_and_you_may_optimize_based_on_my_good_word_upon_penalty_of_undefined_behaviour()
- derefr 6y agoI mean, what other semantics would anyone expect it to have—presuming they think for a moment about why it exists as its own thing in the first place?
- dodobirdlord 6y agoRust being Rust, the equivalent causes a safe teardown. https://doc.rust-lang.org/std/macro.unreachable.html https://doc.rust-lang.org/std/macro.unreachable.html The UB causing equivalent is of course unsafe. https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked....
- jstimpfle 6y agoOk so what's the answer if you apply the question to __builtin_trap()?
- saagarjha 6y agoEven better, just actually perform undefined behavior on that branch and the compiler will get rid of it.