Bug 5814 – A bug with bitwise and among booleans

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-04T15:45:00Z
Last change time
2011-07-09T11:08:24Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-04-04T15:45:00Z
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.
Comment #1 by bearophile_hugs — 2011-07-09T11:08:24Z
*** This issue has been marked as a duplicate of issue 5409 ***