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: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@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: -------

Reply via email to