News for hackers. Stuff that matters.
Re:This should never happen by someguy1234 on Thursday March 31, 2016 @09:37AM (#11397013)
Sometimes you do it because the compiler insists a case (that really can never happen) needs to be handled.

It happens a lot to me in Rust and Go.

Re:This should never happen by masklinn on Thursday March 31, 2016 @09:49AM (#11397104)
Re:This should never happen by cpeterso on Thursday March 31, 2016 @12:03PM (#11398161)
Note that gcc and clang's __builtin_unreachable() are optimization pragmas, not assertions. If control actually reaches a __builtin_unreachable(), your program doesn't necessarily abort. Terrible things can happen such as switch statements jumping into random addresses or functions running off the end without returning:

https://raw.githubusercontent.com/bjacob/builtin-unreachable...

Re:This should never happen by nightpool on Thursday March 31, 2016 @12:32PM (#11398439)
Sure, these aren't for defensive programming—they're for places where you know a location is unreachable, but your compiler can't prove it for you. The example given in the rust docs, for example, is a match clause with complete guard arms (i.e. if n < 0 and if n >= 0).