Bug 1792 – illegal opAssign possible via alias

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-01-19T04:35:38Z
Last change time
2019-07-16T04:09:50Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Frank Benoit

Comments

Comment #0 by benoit — 2008-01-19T04:35:38Z
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; }
Comment #1 by smjg — 2008-09-09T16:21:48Z
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.
Comment #2 by pro.mathias.lang — 2019-07-16T04:09:50Z
The compiler gives an error ("class `mod.C` identity assignment operator overload is illegal") in D2.