== Quote from Daniel Gibson (metalcae...@gmail.com)'s article > Leandro Lucarella schrieb: > > 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); > > } > > > > ? > > > Obviously he wants a portable way to do this that will work on any up-to-date > D2 compiler.. doesn't > make much sense to have a gdc-only solution that makes code incompatible with dmd (and possibly > other compilers). Of course one may use version(GDC) or something like that to ensure compatibility, > but that's just ugly. > Cheers, > - Daniel
The GNU_attribute pragmas are just hints to the GCC backend; very limited in what they do; don't really thrive very well in D's environment. Take for example: pragma (GNU_attribute, vector_size(16)) typedef int MyInt; And you have a MyInt data type that is 16bytes wide, but D will still report that it is 4, and you can't use or assign anything to it either (else we'll ICE). I guess it is a WIP feature that got left behind, I could have a look at it improving it sometime, but I haven't really seen any benefits in reviving it though...