On Tue, 19 Aug 2014 22:28:25 +0000 Peter Alexander via Digitalmars-d <[email protected]> wrote:
> The rule in the spec is "The lexically first ReturnStatement > determines the ref-ness of [an auto ref] function" > > Why is this? I think it would be more consistent and convenient > to be: "An auto ref function returns by ref if all return paths > return an lvalue, else it returns by value". first: compilation speed. compiler can stop looking at function just after the first 'return'. second: it's easier to human to determine the actual return type this way. imagine that you want to return refs, and somewhere deep in your code you accidentaly returns some literal. it can take ages to figure out what happens. just add something like "if (0) return 42;" to foo(). compiler will eliminate dead code, but will use 'return 42' to determine function return type.
signature.asc
Description: PGP signature
