Summary: Disallow (!x & y)
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 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

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

// 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:
searching for "Correct occurrences of !x&y".

An example:;a=commit;h=b2d7c7f7a69fd953626c3e507bac70e18b21f70e

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to