www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1792] New: illegal opAssign possible via alias

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

           Summary: illegal opAssign possible via alias
           Product: D
           Version: 1.025
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: benoit tionex.de


From http://digitalmars.com/d/1.0/operatoroverloading.html
The assignment operator cannot be overloaded for rvalues that can be implicitly
cast to the lvalue type.

Doing so results in a compiler error. 
But doing it via an alias, the compiler does not complain.

class C{
  C set( C c ){ return c; }
  alias set opAssign;
}


-- 
Jan 19 2008
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1792


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




------- Comment #1 from smjg iname.com  2008-09-09 16:21 -------
The compiler accepts the code, but the assignment operator doesn't actually
overload:
----------
import std.stdio;

class C {
    C set(C c) {
        writefln("Calling C.set");
        return c;
    }
    alias set opAssign;
}

void main() {
    C d = new C;
    C e = new C;
    d = e;
}
----------
generates no output on run.


-- 
Sep 09 2008