auto ref deduction and common type deduction inconsistency

Peter Alexander via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 20 08:08:48 PDT 2014


On Wednesday, 20 August 2014 at 14:52:59 UTC, ketmar via 
Digitalmars-d wrote:
> On Wed, 20 Aug 2014 14:44:40 +0000
> Peter Alexander via Digitalmars-d <digitalmars-d at puremagic.com> 
> wrote:
>
>> Well, the return type is already the common type of all return 
>> paths
> no, it's not. the return type will be taken from the first 
> return
> statement in code.

auto foo() {
   if (1) return 1;
   return 2.0;
}

This returns double. Try for yourself.

>> That doesn't help at all. I want return by ref when possible, 
>> not always return by value. If I wanted return by value, I'd 
>> just return by value!!
> you can't return ref and non-ref simultaneously from one 
> function.

Of course, what I want is:

1. If both returns are lvalues, return by ref.
2. Otherwise, return by rvalue (regardless if one is an lvalue).


More information about the Digitalmars-d mailing list