auto ref deduction and common type deduction inconsistency
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 20 08:28:57 PDT 2014
On Wed, 20 Aug 2014 15:08:48 +0000
Peter Alexander via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> auto foo() {
> if (1) return 1;
> return 2.0;
> }
>
> This returns double. Try for yourself.
i wasn't talking about integer promotions, but yes, it works here. and
i'm sure that is shouldn't -- i consider this as a bug.
> 1. If both returns are lvalues, return by ref.
> 2. Otherwise, return by rvalue (regardless if one is an lvalue).
see above. now i understand you, but i think that any kind of type
conversions should try to convert to the type of the first return (i.e.
promote int to double if first return returnd 2.0, but emit error if
first return returns int and second trying to return float).
and for (cond ? x : 42) compiler should emit error too, 'cause
exact return type can't be determined. maybe it should do this only for
'auto ref' though.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140820/324c40bb/attachment.sig>
More information about the Digitalmars-d
mailing list