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@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@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users >
_______________________________________________ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users