[Issue 259] Comparing signed to unsigned does not generate an error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 21 22:05:36 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=259

--- Comment #73 from thomas.bockman at gmail.com ---
(In reply to Stewart Gordon from comment #72)
> I don't understand.  How can code that the spec explicitly forbids possibly
> be correct?

Normal programmers, who are not language lawyers, generally consider code to be
correct if it reliably does what it is intended to do, in the way it is
intended to do it.

They do not know or care what the language spec says, and they assume the
compiler can be trusted to enforce such simple rules as "mixed signed-unsigned
comparisons are forbidden", if necessary.

And, this is a perfectly rational approach, since both the compiler and the
spec are complex, change over time, and sometimes contradict each other. Where
there is a conflict, a programmer must satisfy the compiler in order to get
work done, while the spec is important only in theory.

Regardless of what the spec says, the de-facto semantics of the D language are
that mixed signed-unsigned integer comparisons in D use integer promotion, like
other mixed operations.

That can certainly be changed, but the compiler needs to point out code that
needs to be updated for the new semantics via warnings, deprecations, or
errors.

People need to be able to write code and then move on with their lives, and
must not be forced to memorize the language spec and manually review all of the
code they have ever written in D every time a new version of the compiler or
spec comes out, to avoid silent breakage.

--


More information about the Digitalmars-d-bugs mailing list