Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> But shouldn't this be a compiler directive?

Lisp perspective: anything that can be a function almost certainly should be a function (and not a special operator or macro).

std::unreachable() does not have any arguments; therefore it doesn't need any special argument evaluation semantics that would require a compiler built-in.

The way C and C++ work, compiler directives are keywords and not identifiers. Keywords are not namespaced. Introducing a keyword called "unreachable" is problematic; far more so than a new element in the std namespace.

My only problem with std::unreachable is that I would never use it over std::abort.

Nobody needs a function whose only job is to invoke undefined behavior (from which it is then assumed that it is not reached).

It's a good cold day, so I can almost hear the Rust people laughing in the distance.



To be clear, Rust has this exact same functionality, with an intrinsic as well as a regular function that wraps said intrinsic.

The only difference is that it’s marked unsafe.

https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked....

There is a safe version that is just a wrapper around panic! with a standardized message.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: