[cfe-users] Unexpected (IMO) constant-conversion warning

David Blaikie via cfe-users cfe-users at lists.llvm.org
Mon Jun 25 10:20:28 PDT 2018


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.

On Wed, Jun 20, 2018 at 6:35 PM Szymon Zimnowoda via cfe-users <
cfe-users at lists.llvm.org> wrote:

> Hello, consider following code:
> https://godbolt.org/g/UN8xTy <https://godbolt.org/g/n3Rt9D>
>
> I do not understand, why overflow warning is here, there is no explicite
> int in this code.
> When removing constexpr, warning disappears, when changing to:
>
> static constexpr uint8_t b = uint8_t{~a};
>
> warning disappears.
>
> Could someone explain it to me?
>
>
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20180625/deaf1836/attachment.html>


More information about the cfe-users mailing list