GCC 4.9.1 reports "warning: conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion]" with the following code
#include <cstdlib>
int main( int , char*[] ) {
unsigned char *dest = new unsigned char[16];
const unsigned char *src = new unsigned char[16];
for( size_t i = 0; i != 16; ++i) {
dest[i] = ~(src[i]);
}
return 0;
}
Obviously, both src and dest are both pointers to an array of unsigned char and I only want the latter to be the bit-wise negation of the former. For some strange reason the ~ operator seems to return an int and thus triggering the warning. Why? Is this intended behaviour?
Of course, I know I could use a static_cast<unsigned char>() to prevent the warning, but I feel that something else is wrong and the warning should not be there in the first place.