www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2205] New: Warning on comparison between signed and unsigned

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2205

           Summary: Warning on comparison between signed and unsigned
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: o.dathe gmx.de


The following code does not generate a warning when compiled with -w.

  int a=-1;
  uint b=1;
  assert (a<b);

The assertion failes since the comparison is done unsigned. I think it is a
very basic and frequent source of errors and should be taken into account if
warnings are enabled - just like in gcc -W.


-- 
Jul 08 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d-bugmail puremagic.com> wrote in message 
news:bug-2205-3 http.d.puremagic.com/issues/...
 http://d.puremagic.com/issues/show_bug.cgi?id=2205

           Summary: Warning on comparison between signed and unsigned
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: o.dathe gmx.de


 The following code does not generate a warning when compiled with -w.

  int a=-1;
  uint b=1;
  assert (a<b);

 The assertion failes since the comparison is done unsigned. I think it is 
 a
 very basic and frequent source of errors and should be taken into account 
 if
 warnings are enabled - just like in gcc -W.

Completely agree. I can't tell you how many times I've done for(uint i = x; i >= 0; i--) ... Infinite loop!
Jul 08 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2205


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |diagnostic




------- Comment #1 from smjg iname.com  2008-07-08 19:48 -------
I'd like this to either:
- be an error
- promote both sides to long
- generate some code resembling
    assert (a < 0 || cast(uint) a < b);


-- 
Jul 08 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2205


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
           Keywords|diagnostic                  |accepts-invalid
         Resolution|                            |DUPLICATE




------- Comment #2 from smjg iname.com  2009-02-22 11:45 -------
I've just checked, and by spec it's supposed to be an error.

*** This bug has been marked as a duplicate of 259 ***


-- 
Feb 22 2009