This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34198] -Wconversion gives apparent erroneous warning with g++ 4.3-20071109
- From: "fang at csl dot cornell dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Nov 2007 21:52:08 -0000
- Subject: [Bug c++/34198] -Wconversion gives apparent erroneous warning with g++ 4.3-20071109
- References: <bug-34198-15412@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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