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

           Summary: CTFE: wrong code for if(x) where x is int or smaller
           Product: D
           Version: 1.051
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: clugd...@yahoo.com.au


--- Comment #0 from Don <clugd...@yahoo.com.au> 2009-12-15 14:12:33 PST ---
Applies to while(), if(), assert(), etc.
Also happens if you have (say) uint u = 0x8000_0000; u<<=1;
-- since this sets the high bit of the value to 1.

TEST CASE:
----
int foo() {
   int u = cast(int)(0x1_0000_0000L);
   while (u) {
      if (u) { 
         assert(u!=0); 
        }
      assert(u!=0);
   }
   return 2;
}
static assert(foo()==2);
--------------------
PATCH: expression.c, around line 1575.
Need to convert the value to an appropriate sized integer.

int IntegerExp::isBool(int result)
{
+    toInteger();
    return result ? value != 0 : value == 0;
}

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

Reply via email to