digitalmars.D - unsigned < 0
- bearophile (21/21) Feb 10 2011 Recently I have shown some bugs (and added few enhancement requests):
- bearophile (4/5) Feb 10 2011 To avoid troubles in generic code you need a little workaround:
- bearophile (3/5) Feb 10 2011 That's not good enough yet. The first part of the test needs to be done ...
- Iain Buclaw (7/12) Feb 11 2011 You also need to watch out for code like this too:
- bearophile (4/7) Feb 11 2011 I was not talking about warnings. I was talking about changing the D lan...
Recently I have shown some bugs (and added few enhancement requests): http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=129069 Among those there is my suggestion to statically disallow unsigned<0 comparisons: http://d.puremagic.com/issues/show_bug.cgi?id=5539 So that's a little change in the D2 language itself, it's not a warning as the one GCC shows on C code. Recently Iain Buclaw has shown some patches for DMD: http://d.puremagic.com/issues/show_bug.cgi?id=5490 Three cases were of unsigned < 0, like: +++ b/src/optimize.c -351,7 +351,7 Expression *AddrExp::optimize(int result) { TypeSArray *ts = (TypeSArray *)ve->type; dinteger_t dim = ts->dim->toInteger(); - if (index < 0 || index >= dim) + if (index >= dim) error("array index %jd is out of bounds [0..%jd]", index, dim); e = new SymOffExp(loc, ve->var, index * ts->nextOf()->size()); e->type = type; Do you like this little change in the D2 language? Bye, bearophile
Feb 10 2011
Do you like this little change in the D2 language?To avoid troubles in generic code you need a little workaround: if (__traits(isUnsigned, x) || x >= 0) { ... Bye, bearophile
Feb 10 2011
To avoid troubles in generic code you need a little workaround: if (__traits(isUnsigned, x) || x >= 0) { ...That's not good enough yet. The first part of the test needs to be done in a static if. Bye, bearophile
Feb 10 2011
== Quote from bearophile (bearophileHUGS lycos.com)'s articlestatic if.To avoid troubles in generic code you need a little workaround: if (__traits(isUnsigned, x) || x >= 0) { ...That's not good enough yet. The first part of the test needs to be done in aBye, bearophileYou also need to watch out for code like this too: if (T.min < 0) { ... As that could possibly trigger off unsigned < 0 warnings too. Regards Iain
Feb 11 2011
Iain Buclaw:You also need to watch out for code like this too: if (T.min < 0) { ... As that could possibly trigger off unsigned < 0 warnings too.I was not talking about warnings. I was talking about changing the D language, turning that into a _error_ if x is unsigned. Bye, bearophile
Feb 11 2011