www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3483] New: Eliminate read-modify-write operations for enums

reply d-bugmail puremagic.com writes:
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



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: -------
Nov 06 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3483


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com



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: -------
Nov 08 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3483




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: -------
Nov 20 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3483




16:54:22 PST ---

 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: -------
Nov 20 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jun 29 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 09 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3483


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 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: -------
Oct 09 2011