Stewart Gordon wrote:
Walter Bright wrote:
BCS wrote:
IIRC D allows "return exp;" in a void function because it avoids special cases in template code.

ReturnTypeOf!(AFn, T) fn(T)(T t)
{
   return AFn(t,t); // AFn might return void
}

Yes, that's exactly why.

Why it allows you to return an int from a void-returning function???

C does that, too.

void foo()
{
    return 23;
}

int  main()
{
    foo();
}

Running the program gives random values as the exit status.
Changing void to int returns always 23.

(Actually I would have thought that it'd give 23 in both cases.
But I guess the assignment of 23 into the return register doesn't
get compiled when void is used.)

----

Anyway, I don't think this is such a big deal. Fixing this may be a lot of work, and I haven't heard anyone complain about it, in C or D, before.

It's a blemish, but one we can live with.

Reply via email to