A never type represents an expression that is never evaluated or the type of an expression that represents an unreachable point in a program. The return value of an
abort() function could be of such a type. C partially implements this for functions only as
_Noreturn but this is only a specifier and not a distinct type.
A more useful implementation would include semantics such as:
- Being a type:
never_type abort(void);instead of a specifier
_Noreturn void abort().
- Being implicitly convertible to any type:
int x = abort();. The function never returns, so matching the nonexistent return 'value' to the expected type of the expression is irrelevant.
__builtin_unreachable()would have this type. These are used to designate points of the program that will never be reached during execution by the program control flow. In C these are just
voidtyped and invoke undefined behavior if reached.
Rust has a 'never' type but many languages do not. Are there any disadvantages to including this type?