gcc 4.3.0, -Wconversion: assignment-by operators for shorter types

Andriy Gapon avg@icyb.net.ua
Mon May 26 17:37:00 GMT 2008


If I write something like the following:
uint8_t x;
uint8_t y;
x ^= y;

and compile with gcc 4.3.0 with  -Wconversion option, then I get the
following warning:
warning: conversion to ‘unsigned char’ from ‘int’ may alter its value
[-Wconversion]

While technically this warning is correct (because x and y are
implicitly advanced to "int"before actual xor operation), it seems that
it doesn't make much practical sense.

I think that this applies to all "assignment-by" operators working on
types shorter than int.

OTOH, proper implementation should be smart enough to warn about the
following:
uint8_t x;
uint16_t y;
x ^= y;


-- 
Andriy Gapon



More information about the Gcc mailing list