www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4041] New: Error with ref or auto ref return from opOpAssign

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4041

           Summary: Error with ref or auto ref return from opOpAssign
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: aldacron gmail.com


--- Comment #0 from Mike Parker <aldacron gmail.com> 2010-04-01 18:26:25 PDT ---
##############################
struct Foo
{
    int x;

    ref Foo opOpAssign(string op)(ref Foo f) if(op == "+=")
    {
        x += f.x;
        return this;
    }
}

void main()
{
    Foo f1 = Foo(1);
    Foo f2 = Foo(2);
    f2 += f1;
}
#################################

Results in: 

refret.d(5): Error: variable refret.Foo.op only parameters or foreach
declaratio
ns can be ref

Change the return type from 'ref Foo' to 'auto ref Foo' and the same error
occurs. Remove the ref from the return and it compiles. Comment out the 'f2 +=
f1' and it compiles.

This happens on both 2.041 and 2.042. I haven't tried earlier versions.

BTW, 2.042 is missing from the version list here on Bugzilla.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4041


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com


--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-09-25 18:19:48 PDT
---
*** Issue 4934 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4041


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2011-06-20 02:17:53 PDT ---
Trivial fix of sample code:
----
struct Foo
{
    int x;

    ref Foo opOpAssign(string op)(ref Foo f) if(op == "+")  // <- "+="
    {
        x += f.x;
        return this;
    }
}
void main()
{
    Foo f1 = Foo(1);
    Foo f2 = Foo(2);
    f2 += f1;
}
----

And, on dmd 2.054 (d36b3b12fc4814e59f3a0d680b8700e787b1ceff) this code has
passed to compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4041


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
            Version|2.041                       |D2
         Resolution|                            |WORKSFORME
         OS/Version|Windows                     |All


--- Comment #3 from yebblies <yebblies gmail.com> 2012-02-01 21:10:52 EST ---
I can't reproduce this.

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