[Issue 10480] New: Warning against wrong usage of incorrect operator for bits set test

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 26 11:05:24 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10480

           Summary: Warning against wrong usage of incorrect operator for
                    bits set test
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          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 2013-06-26 11:05:24 PDT ---
The D compiler 2.064alpha gives no warnings here:


bool someFunction() { return true; }
uint getFlags() { return uint.max; }
void main() {
    uint kFlagValue = 2u ^^ 14;
    if (someFunction() || getFlags() | kFlagValue) {}
}




enum INPUT_VALUE = 2;
void f(uint flags) {
    if (flags | INPUT_VALUE) {}
}


The warning given by Visual Studio 2012:
http://msdn.microsoft.com/en-us/library/f921xb29.aspx

warning C6316: Incorrect operator:  tested expression is constant and non-zero.
 Use bitwise-and to determine whether bits are set.<


More info:
http://randomascii.wordpress.com/2013/06/24/two-years-and-thousands-of-bugs-of-/

Perhaps it's a good idea to add this warning to D/dmd.

-- 
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