Bug 3280 – comparing array length is wonky

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-09-01T16:39:00Z
Last change time
2015-06-09T01:28:08Z
Assigned to
nobody
Creator
ellery-newcomer

Comments

Comment #0 by ellery-newcomer — 2009-09-01T16:39:31Z
void main(){ string s; int a = s.length; assert(a == 0); assert(s.length == 0); assert(a == 0); assert(a > -1); assert(s.length > -1); //fails }
Comment #1 by jarrett.billingsley — 2009-09-01T17:09:24Z
Sorry, invalid. typeof(s.length) is unsigned, typeof(-1) is signed. The compiler should throw an error on the last assert, but doesn't. Instead, it casts -1 to size_t, resulting in something like "assert(s.length > 0xFFFFFFFF);" See bug 259.
Comment #2 by jarrett.billingsley — 2009-09-01T17:09:39Z
Oops