The "Operator Overloading" page of the spec says that: "...the following parameter signatures for opAssign are not allowed: ... opAssign(T) ... where T is the same type as the aggregate type A..." However, the following compiles: import std.stdio; struct S { S opAssign(T)(T t) { writeln(T.stringof); return this; } } void main() { S a, b; a = b; } When run, it prints 'S'.
I am using DMD 2.043.
D2 spec is updated for struct. http://dlang.org/operatoroverloading#assignment > For struct types, operator overloading for the identity assignment is allowed. ... > However for class types, identity assignment is not allowed. And for class types, identity opAssign definition is properly checked, even if it's template. class C { C opAssign(T)(T t) // line 3 { writeln(T.stringof); return this; } } void main() {} Output: test.d(3): Error: class test.C identity assignment operator overload is illegal