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?
> 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
> 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
gt; Bye,
> bearophile
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.
Regards
Iain
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