<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 18 February 2018 at 05:36, Dmitry Olshansky via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sunday, 18 February 2018 at 01:09:57 UTC, Manu wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On 5 February 2018 at 11:22, H. S. Teoh via Digitalmars-d < <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
<br>
</span><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Code:<br>
<br>
        struct S {<br>
                byte[2] x;<br>
        }<br>
        void main() {<br>
                S s, t;<br>
                s.x = [ 1, -1 ];                // OK<br>
                t.x = [ -s.x[0], -s.x[1] ];     // NG (line 7)<br>
        }<br>
<br>
<br>
Compiler says:<br>
        /tmp/test.d(7): Deprecation: integral promotion not done for<br>
`-s.x[0]`, use '-transition=intpromote' switch or `-cast(int)(s.x[0])`<br>
        /tmp/test.d(7): Deprecation: integral promotion not done for<br>
`-s.x[1]`, use '-transition=intpromote' switch or `-cast(int)(s.x[1])`<br>
<br>
<br>
Why should I need to explicitly cast to int only to reassign it back to byte?!  This is ridiculous.<br>
</blockquote>
<br>
<br></span><span class="">
Seriously, WTF is going on here?<br>
</span></blockquote>
<br>
C compilers did it for ages, but D doesn’t auto promote to int on unary ops. Hence the warning, the suggestion is kinda stupid thiugh.<br>
<br>
C gets away by truncating results silently on assign of int to byte</blockquote><div><br></div><div>The 'solution' so add cast(int) and then cast back is not okay. I have code that does a lot of work on bytes/shorts (colour components are small integers that receive a lot of maths), and most lines get 3-4 times longer because of these casts...<br></div><div>I can't accept that.<br><br></div><div>If change the behaviour (is done), then just let the code be broken! Emitting these terrible noises, and encouraging people to make their code even noisier than the compiler output is much worse than broken code.<br></div><div>
There are hundreds of lines I need to molest to make the compiler shut up.

I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.<br></div></div></div></div>