[Issue 17336] Implicit type conversion of size_t.init to int causes standard type compatibility test to break

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Apr 20 12:41:18 PDT 2017


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

Adam D. Ruppe <destructionator at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator at gmail.com

--- Comment #1 from Adam D. Ruppe <destructionator at gmail.com> ---
I don't think this is a bug at all, it is exactly what VRP is supposed to do -
if the value is guaranteed to be in range, allow the implicit cast. This is why
`ubyte a = 0;` compiles at all; typeof(0) == int, but vrp proves it fits in
ubyte so no cast required. The compiler could prove it in the case of `init`
since it is statically known in the expression, but failed to prove it in the
other case since VRP doesn't cross statements.

BTW also note that size_t *may be* `int` as well - that's the case on 32 bit
builds. There's no error at all with -m32, so your test is buggy regardless
IMO.


I do kinda agree though that if you do explicitly cast, the compiler shouldn't
implicitly cast it right back, which it does (and the compiler likes to insert
fake explicit casts into the AST as it goes, giving error messages saying casts
exist that the coder didn't write, so it'd have to clean that up too), but I'm
still hesitant to actually call it a bug since it is working exactly as
designed.

--


More information about the Digitalmars-d-bugs mailing list