return in void functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 4 22:24:38 PST 2009


Nick Sabalausky wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message 
> news:gomvoo$1m3b$3 at digitalmars.com...
>> 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.
> 
> There has to be a better way to handle that.  Making "void foo(){return 1;}" 
> valid code with no warning is just plain sloppy. (In fact, I've been bitten 
> by that before.) 
> 
> 

I agree. It's fine to forward a void to a void, but not anything else to 
a void.


Andrei



More information about the Digitalmars-d mailing list