Comment #0 by verylonglogin.reg — 2012-10-30T08:47:15Z
Disabling ++, -- and assignments to non-lvalues (opAssign, opOpAssign, opIndexAssign, opIndexOpAssign, opSliceAssign, opSliceOpAssign) will allow to define user types with same semantics as build-in types (arithmetic and static arrays):
---
struct S
{
void opUnary(string op : "++")() { }
void opAssign(int) { }
}
int iFunc() { return 0; }
int[1] sarrFunc() { return [0]; }
S sFunc() { return S(); }
void main()
{
++int.init; // Error: constant 0 is not an lvalue
++iFunc(); // Error: iFunc() is not an lvalue
++(int[1]).init; // Error: [0] is not an lvalue
++sarrFunc(); // Error: sarrFunc() is not an lvalue
// currently compiles, but shouldn't:
++S.init;
++sFunc();
S.init = 3;
sFunc() = 3;
}
---
Comment #1 by robert.schadek — 2024-12-13T18:02:14Z