Daren Scot Wilson <[email protected]> wrote:
As shown, the "total evil" return statement gets a value from subroutine
foo(). Being somehow so perfect in its evilness, this passes through
the compiler without a burp. The resulting executable returns zero (or
my bash shell defaults to zero when receiving nothing.)
This is by design, the feature is made for generic functions. Consider:
ReturnType!Fn wrap( alias Fn )( ParameterTypeTuple!Fn args ) {
return Fn( args );
}
One would expect that to work. If void functions did not allow returning
the results of functions, the above function would have had to be changed
to something like this:
ReturnType!Fn wrap( alias Fn )( ParameterTypeTuple!Fn args ) {
static if ( is( typeof( return ) == void ) ) {
Fn( args );
} else {
return Fn( args );
}
}
Clearly this code is worse than the above.
--
Simen