Bug 8916 – How about to disable ++, --, and assignments to non-lvalues?

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-30T08:47:15Z
Last change time
2024-12-13T18:02:14Z
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18482 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18482 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB