g++ 4.3.3 emits warnings for every statement in the following function when the code is built this way: ..../gcc43/bin/g++ -c -Wall -Wconversion test.cpp void func(unsigned char a, unsigned char b, unsigned char *out) { *out = a | b; *out = out[0] & 0x20; out[0] &= 0x20; } I'd expect bitwise operators to see/preserve argument widths...
Created attachment 17238 [details] The test case
Original description is not quite accurate, the or operator does not cause a spurious warning while the and operator does. Here is a more minimal test case: void func(char a, char b, char c) { c = a | b; c = a & b; c = a | 0x20; c = a & 0x20; // warn } I do not get the spurious warning in SVN from 20090109.
After talking with Oleg, there are differences between gcc and g++ compiling the code in comment #2: $ g++ --version g++ (GCC) 4.3.0 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -Wconversion and_or_conversion.c -c and_or_conversion.c: In function ‘void func(char, char, char)’: and_or_conversion.c:3: warning: conversion to ‘char’ from ‘int’ may alter its va lue and_or_conversion.c:4: warning: conversion to ‘char’ from ‘int’ may alter its va lue and_or_conversion.c:6: warning: conversion to ‘char’ from ‘int’ may alter its va lue $ gcc -Wconversion and_or_conversion.c -c and_or_conversion.c: In function ‘func’: and_or_conversion.c:6: warning: conversion to ‘char’ from ‘int’ may alter its va lue I get the same results with GCC 4.3.2 as packaged by Fedora 10: $ g++ --version g++ (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7) Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I think this is a duplicate of bug 38522 which is fixed for 4.4.0.
I've just built gcc 4.4 and it emits no warnings for the test case above. Is there any chance the fix could be back-ported into 4.3?
Created attachment 17239 [details] The fix from gcc4.4 This is the naive fix merged from the trunk. Fixes two out of three warnings in C++ mode.
*** This bug has been marked as a duplicate of 38522 ***