http://d.puremagic.com/issues/show_bug.cgi?id=3167


Steven Schveighoffer <schvei...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schvei...@yahoo.com


--- Comment #14 from Steven Schveighoffer <schvei...@yahoo.com> 2010-01-29 
19:24:11 PST ---
(In reply to comment #13)
> It is invalid code because you are taking a reference to the return value of a
> function. Functions return, by definition, rvalues. You cannot take a 
> reference
> to an rvalue.

This breaks custom types.  Who are you as the compiler to assume my type is an
rvalue?

e.g.

class MyClass
{
   struct myForwardRange {...}
   @property myForwardRange all() {...}   
}

void copy(R1, R2)(ref R1 inputrange, ref R2 outputrange)
{
...
}

void foo(MyClass mc, OutputRange r)
{
   copy(mc.all, r);
}

Another case:

struct LargeStruct
{
  int[100] bigarray;
  void print(streamtype s) {s.print(bigarray);}
}

class X
{
  LargeStruct createalargestruct() {...}
}

void foo(X x)
{
  x.createalargestruct().print(stdout);
}

Also, if you can't call properties on a struct, which essentially needs a
reference to the struct, then you can't get any properties from a returned
struct.

This rule is way too limiting.  at the very least, const rvalue references need
to be allowed for any reasonable value types that are not just POD to be
created.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to