[Bug c++/34198] -Wconversion gives apparent erroneous warning with g++ 4.3-20071109

fang at csl dot cornell dot edu gcc-bugzilla@gcc.gnu.org
Thu Nov 22 21:52:00 GMT 2007



------- Comment #3 from fang at csl dot cornell dot edu  2007-11-22 21:52 -------
I'm having some issues with this as well (same snapshot):

some more tests:

void f(const unsigned char b)
{
 unsigned char c = static_cast<unsigned char>(b & 0xff);
 unsigned char d = (unsigned char)(b & 0xff);
 char e = static_cast<char>(b & 0xff);
 char f = char(b & 0xff);
}

pr34198.cc:4: error: conversion to 'unsigned char' from 'int' may alter its
value
pr34198.cc:5: error: conversion to 'unsigned char' from 'int' may alter its
value
pr34198.cc:6: error: conversion to 'unsigned char' from 'int' may alter its
value
pr34198.cc:7: error: conversion to 'unsigned char' from 'int' may alter its
value

I'm trying to understand all the reasonings: http://gcc.gnu.org/wiki/Wcoercion
IMHO, the explicit casts (static_cast or function-style) should suppress the
warnings.


-- 

fang at csl dot cornell dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fang at csl dot cornell dot
                   |                            |edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34198



More information about the Gcc-bugs mailing list