<div dir="ltr">Yeah, the problem is that '~a' is an expression of type 'int' due to something called "the usual arithmetic conversions" - basically in almost any arithmetic expression in C++, all the smaller int types get promoted up to int (this is oversimplifying a bit - but sufficient here - if you look up that phrase you'll find a more detailed description) and then the arithmetic is done. So there's an implicit widening from uint8_t to int of the 'a' before the ~ is done. So you have to cast back down. </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 20, 2018 at 6:35 PM Szymon Zimnowoda via cfe-users <<a href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div><span class="m_5191079127158630545gmail-_5yl5"><span>Hello, consider following code:<br></span></span></div><div><span class="m_5191079127158630545gmail-_5yl5"><span><a href="https://godbolt.org/g/n3Rt9D" rel="nofollow" target="_blank">https://godbolt.org/g/UN8xTy</a><br></span></span></div><div><br></div><div>I do not understand, why overflow warning is here, there is no explicite int in this code.</div><div>When removing constexpr, warning disappears, when changing to:</div><div><br></div><div>
<span class="m_5191079127158630545gmail-_5yl5"><span>static constexpr uint8_t b = uint8_t{~a};</span></span> </div><div><br></div><div>warning disappears.</div><div><br></div><div>Could someone explain it to me?<br></div><div><br></div><div><br><span class="m_5191079127158630545gmail-_5yl5"><span></span></span> </div></div>
_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</blockquote></div>