consider following code:
#include <iostream>
static constexpr uint8_t a = 0x80;
static constexpr uint8_t b = ~a;
It produces the following warning:
<source>:5:30: warning: implicit conversion from 'int' to 'const uint8_t' (aka 'const unsigned char') changes value from -129 to 127 [-Wconstant-conversion]
static constexpr uint8_t b = ~a;
I do not understand, why overflow warning is here, there is no explicite int in this code. I am operating on variables with the same type. When removing constexpr, warning disappears, when changing to:
static constexpr uint8_t b = uint8_t{~a};
warning disappears. So looks like ~ operator implicite changes variable to int?
Could someone explain it to me?
Aucun commentaire:
Enregistrer un commentaire