[Bug c++/34198] -Wconversion gives apparent erroneous warning with g++ 4.3-20071109
manu at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Nov 22 22:43:00 GMT 2007
------- Comment #4 from manu at gcc dot gnu dot org 2007-11-22 22:43 -------
(In reply to comment #3)
> IMHO, the explicit casts (static_cast or function-style) should suppress the
> warnings.
That is not the problem. The explicit casts suppress the warnings for the
implicit conversion that occurs in the assignment. However, the C/C++
front-ends create an additional implicit conversion that is applied to 'b' and
that I don't see how it can be avoided.
See that if you try with:
void f(const unsigned char b)
{
unsigned char c = b & 0xff;
}
you get two warnings:
test.C:3: warning: conversion to âÂÂunsigned charâ from âÂÂintâ may alter
its value
test.C:3: warning: conversion to âÂÂunsigned charâ from âÂÂintâ may alter
its value
Also if you try:
void f(const unsigned char b)
{
if (b & 0xff) {
return;
}
}
you still get a warning!
test.C:3: warning: conversion of âÂÂ(int)bâ to âÂÂunsigned charâ from
âÂÂintâ may alter its value
This also affects the C front-end since the code is shared and they seem to do
exactly the same thing. Perhaps convert_and_check is called in a place where it
shouldn't be called. Or perhaps something is building '(int)b' when it should
just leave 'b' alone. Any ideas?
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-11-22 22:43:19
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34198
More information about the Gcc-bugs
mailing list