@noreturn property

Iain Buclaw ibuclaw at ubuntu.com
Thu Oct 21 08:58:49 PDT 2010


== Quote from Leandro Lucarella (luca at llucax.com.ar)'s article
> Iain Buclaw, el 21 de octubre a las 11:54 me escribiste:
> > 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.
> >
> > Example:
> >
> > int mycheck(int x)
> > {
> >     if (x > 1)
> >         return OK;
> >     fatal();
> > }
> >
> >
> > Thoughts?
> You want to include in the language what you can do (or at least could)
> do in GDC using:
> pragma(GNU_attribute, noreturn)) void fatal()
> {
>      print("Error");
>      exit(1);
> }
> ?

No.

More to the truth, when merging the 2.031 frontend, I found myself having to put
in a lot of assert(0) or returns to satisfy several build errors in the EH unwind
code for Dwarf2. Just seemed like a lot of redundant code to me really. Asked in
#d how useful such a property would be, then I got heckled to post here.


More information about the Digitalmars-d mailing list