Never-returning functions

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 2 08:18:31 PDT 2016


On 8/2/16 11:09 AM, Enamex wrote:
> I've tried to write an 'assert function' in D, one that doesn't trigger
> the 'function must return a value or assert' error.
>
> Basically something like:
>
> Never neverReturns() { assert(0); }
>
> or
>
> @noreturn auto neverReturns() { assert(0); }
>
> and
>
> int tryMe(bool f) {
>     if(f) return 42;
>     else neverReturns();
> }
>
> Then have the call on line 2 in `tryMe` be accepted by the compiler.

What's wrong with assert(0) that you need to have a wrapper function for it?

-Steve


More information about the Digitalmars-d-learn mailing list