[Issue 5814] New: A bug with bitwise and among booleans
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Apr  4 15:48:37 PDT 2011
    
    
  
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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-04-04 15:45:00 PDT ---
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: -------
    
    
More information about the Digitalmars-d-bugs
mailing list