[Issue 5409] New: Disallow (!x & y)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jan 4 04:54:42 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5409
Summary: Disallow (!x & y)
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-01-04 04:52:27 PST ---
Studying bug reports in Linux kernel I've seen many cases like:
!x & y
That were meant to be:
!(x & y)
So I suggest to turn an expression like the first one (!x & y) into a D2 syntax
error.
So the D2 compiler asks the programmer for explicit parentheses like (the two
following cases are both accepted, the error message may show both examples):
!(x & y)
Or even:
(!x) & y
The following case is not covered, this enhancement request is about the
bitwise "&" case only:
!x && y
--------------------------
The Coccinelle tool is able to catch bugs like that with this little semantic
patch:
// Copyright: (C) 2009 Gilles Muller, Julia Lawall, INRIA, DIKU. GPLv2.
@@ expression E1,E2; @@
(
!E1 & !E2
|
- !E1 & E2
+ !(E1 & E2)
)
For some of the (!x & y) Linux bugs caught by Coccinelle see:
http://coccinelle.lip6.fr/impact_linux.php
searching for "Correct occurrences of !x&y".
An example:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b2d7c7f7a69fd953626c3e507bac70e18b21f70e
--
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