www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5814] New: A bug with bitwise and among booleans

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5814

           Summary: A bug with bitwise and among booleans
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



According to this article this D code shows a common bug:
http://www.viva64.com/en/a/0072/


void main() {
    enum uint BAR = 0b011;
    auto foo = 10;
    auto x = !foo & BAR;
}


!foo is a boolean, and usually you don't want to perform a bitwise operation on
a boolean value. So the probable bug in that code is the usage of & instead of
&&.

(This C++ bug is caused by two design decisions: to use the two very similar
symbols && and & to denote two very different operations, and to allow mixing
boolean and integer/bitwise operations).

If this class of bugs is seen as frequent enough, then a possible design
solution to avoid them in D is for D language to not allow the bitwise
operators as & and | to have a boolean operand.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 04 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5814


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 5409 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2011