Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 07, 2009 [Issue 3483] New: Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3483 Summary: Eliminate read-modify-write operations for enums Product: D Version: unspecified Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: andrei@metalanguage.com --- Comment #0 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-11-06 22:16:03 PST --- Consider: enum E { a = 5, b = 10, c = 15; } Arithmetic involving an E are accepted, e.g. E.a + 42, and that's fine because they yield type int which is not convertible back to E. The problem is that read-modify-write expressions are allowed too: E.a x; x += 42; Such operations are nonsensical because they take an enum value easily in places that have nothing to do with the actual defined values. All operations <op>= and also ++ and -- should be disabled for enums. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2009 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 Stewart Gordon <smjg@iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |smjg@iname.com --- Comment #1 from Stewart Gordon <smjg@iname.com> 2009-11-08 06:51:35 PST --- This is going to break uses of enums as bit flags, which is a valid use according to the docs. Maybe we need a separate "bitflags" type, which would differ in this and other respects.... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 20, 2009 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 --- Comment #2 from Stewart Gordon <smjg@iname.com> 2009-11-20 14:55:18 PST --- Moreover, "next value" is a perfectly valid concept for enums, so I don't get why you want ++/-- removed at all. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 21, 2009 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 --- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-11-20 16:54:22 PST --- (In reply to comment #2) > Moreover, "next value" is a perfectly valid concept for enums, so I don't get why you want ++/-- removed at all. It would be just too odd and requiring a lot of complication to define properly. enum E { a = 5, b = 8, c = 15; } Increment of an enum really becomes a series of if/else statements (if it's 5 make it 8 etc.) or would just increment the actual value leading to values that are not part of the enum. What to do? Then what do you do when you are at the end of the scale and want to increment? Answers could be found, the problem is that reasonable people may think different answers are best, and expect different behaviors. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 29, 2011 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |accepts-invalid, patch CC| |yebblies@gmail.com Platform|Other |All OS/Version|Linux |All --- Comment #4 from yebblies <yebblies@gmail.com> 2011-06-30 08:18:55 EST --- Possible solution and phobos changes: https://github.com/D-Programming-Language/dmd/pull/177 https://github.com/D-Programming-Language/phobos/pull/127 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 09, 2011 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |WONTFIX Severity|normal |enhancement --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-10-09 12:59:43 PDT --- I'm going to reject this one. I'm not convinced it is a significant source of bugs, there are many legitimate uses of op= for enums, and the rather loose definition of them is traditional for C. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 09, 2011 [Issue 3483] Eliminate read-modify-write operations for enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://d.puremagic.com/issues/show_bug.cgi?id=3483 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #6 from bearophile_hugs@eml.cc 2011-10-09 13:29:45 PDT --- (In reply to comment #5) > I'm going to reject this one. I'm not convinced it is a significant source of bugs, there are many legitimate uses of op= for enums, and the rather loose definition of them is traditional for C. Time ago I have suggested a @flags attribute to be used on enums that you want to use as bit fields. I vaguely agree with Andrei... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation