On 21/10/2010 10:54 PM, Iain Buclaw wrote:
A few standard library functions, such as 'abort' and 'exit', cannot return. However there is no way in DMD to let the compiler know about this. Currently in D2, you must either have a 'return' or 'assert(0)' statement at the end of a function body. It would be nice however if you can give hints to the compiler to let it know that a function is never going to return.Example: @noreturn void fatal() { print("Error"); exit(1); } The 'noreturn' keyword would tell the compiler that 'fatal' cannot return, and can then optimise without regard to what would happen if 'fatal' ever did return. This should also allow fatal to be used instead of a return or assert statement.
Yes, well, and while others may say that I must be drunk to suggest so, the problem lies in the D type system, albeit, the lack thereof. Further, I know that my previous "canoe" joke did not go down very well or was not understood by the wider D community. Thankfully questions posed by your post give credence to my prior "joke" about the D type system lacking a formal substance (i.e. being close to water). There is a good answer awaiting but it is not a hack such as @noreturn. Cheers Justin Johansson
