January 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #10 from Walter Bright <bugzilla@digitalmars.com> 2010-01-29 11:55:29 PST ---
I'm going to mark this as invalid, as function return values should be rvalues, and rvalues cannot be references, even if the vagaries of the implementation make that possible.

The reason is "vagaries of the implementation", so it may work on one implementation but not another. Currently, whether it (used to) work or not also depended on the contents of the struct being returned.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #11 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-01-29 12:27:07 PST ---
(In reply to comment #10)
> I'm going to mark this as invalid, as function return values should be rvalues, and rvalues cannot be references, even if the vagaries of the implementation make that possible.
> 
> The reason is "vagaries of the implementation", so it may work on one implementation but not another. Currently, whether it (used to) work or not also depended on the contents of the struct being returned.

Why should we leave this to vagaries? An rvalue is not an lvalue, period.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Eldar Insafutdinov <e.insafutdinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |e.insafutdinov@gmail.com


--- Comment #12 from Eldar Insafutdinov <e.insafutdinov@gmail.com> 2010-01-29 15:00:25 PST ---
(In reply to comment #10)
> I'm going to mark this as invalid, as function return values should be rvalues, and rvalues cannot be references, even if the vagaries of the implementation make that possible.
> 
> The reason is "vagaries of the implementation", so it may work on one implementation but not another. Currently, whether it (used to) work or not also depended on the contents of the struct being returned.

This test case fails for me with the latest dmd:

struct X {
}

X i() {
    return X.init;
}

void foo(const ref X x) {
}

void foo() {
    foo(i()); //line 12
}

This bug is not invalid.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167



--- Comment #13 from Walter Bright <bugzilla@digitalmars.com> 2010-01-29 15:50:10 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Steven Schveighoffer <schveiguy@yahoo.com> changed:

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


--- Comment #14 from Steven Schveighoffer <schveiguy@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: -------
February 07, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167



--- Comment #15 from Eldar Insafutdinov <e.insafutdinov@gmail.com> 2010-02-07 03:05:52 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.

But it used to work before.

Just simple case, that I encountered today (I'm sure many of us had similar
experience(:

struct vec3d
{
    double x,y,z;
    static vec3d opCall(double x, double y, double z) { ... }
}

vec3d vecMul(ref const vec3d a, ref const vec3d b)
{
...
}

void main()
{
    vec3d a;
    ...
    vec3d b = opMul(a, vec3d(0., 0., 1.); // doesn't work because opCall
returns rvalue
}

I don't see anything wrong with this code, as const protects arguments from being modified.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 07, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3167



--- Comment #16 from Don <clugdbug@yahoo.com.au> 2010-02-07 07:21:15 PST ---
(In reply to comment #15)
> (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.
> 
> But it used to work before.

It didn't. It only seemed to work. In simple cases it happened to work, in more difficult cases it failed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »