Summary: | -Wconversion is buggy with bitwise operators | ||
---|---|---|---|
Product: | gcc | Reporter: | Oleg Smolsky <oleg.smolsky> |
Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | gcc-bugs, gcc, oleg.smolsky |
Priority: | P3 | ||
Version: | 4.3.3 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | ||
Attachments: |
The test case
The fix from gcc4.4 |
Description
Oleg Smolsky
2009-02-03 17:57:15 UTC
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.
|