www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4558] New: To spot a possible bug in code that doesn't change a value


           Summary: To spot a possible bug in code that doesn't change a
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

--- Comment #0 from bearophile_hugs eml.cc 2010-08-01 14:20:33 PDT ---
This is a semantically wrong D2 program, the programmer has used a "&=" instead
of "|=" to build a flag result:

enum Flags { NONE   = 0b00,
             FIRST  = 0b01,
             SECOND = 0b10
Flags foo(int x) {
    Flags result = Flags.NONE;
    if (x < 10)
        result |= Flags.FIRST;
        result &= Flags.SECOND; // line 10
    return result;
void main() {}

The D compiler can find this problem in the code at line 10 because in that
program the variable "result" is certantly zero after the assignment with
Flags.SECOND, so it's an error or it's useless code.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010