public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40752] New: -Wconversion generates false warnings
@ 2009-07-14 19:17 photon at seznam dot cz
2009-07-14 19:21 ` [Bug c++/40752] " pinskia at gcc dot gnu dot org
` (18 more replies)
0 siblings, 19 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-14 19:17 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 636 bytes --]
-Wconversion generates false warnings for the following clean code:
{
char c = 1;
char c2 = 2;
// warning: conversion to char from int may alter its value
c >>= 1;
c += (char) 1;
c += c2;
c = ~c2;
}
--
Summary: -Wconversion generates false warnings
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: photon at seznam dot cz
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
@ 2009-07-14 19:21 ` pinskia at gcc dot gnu dot org
2009-07-14 20:56 ` manu at gcc dot gnu dot org
` (17 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-14 19:21 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-07-14 19:21 -------
Theses are not false warnings:
c >>= 1;
is really c = (int)c >> 1;
c += (char) 1;
c = (int)c + (int)(char)1;
c += c2;
c = (int)c + (int) c2;
c = ~c2;
c = ~(int)c2;
Only the last one might be a false warning depending on if c2 is negative or
unsigned or not. The rest are correct because of the way C/C++ define
arithmetic operations and automatic promotions.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
2009-07-14 19:21 ` [Bug c++/40752] " pinskia at gcc dot gnu dot org
@ 2009-07-14 20:56 ` manu at gcc dot gnu dot org
2009-07-14 20:56 ` manu at gcc dot gnu dot org
` (16 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-14 20:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from manu at gcc dot gnu dot org 2009-07-14 20:55 -------
Andrew, what you say is true, but in this case the warning is not very useful.
I'd prefer to warn only when the operator is larger than the target of the
assignment. I would like to hear other opinions.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |iant at google dot com, manu
| |at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
2009-07-14 19:21 ` [Bug c++/40752] " pinskia at gcc dot gnu dot org
2009-07-14 20:56 ` manu at gcc dot gnu dot org
@ 2009-07-14 20:56 ` manu at gcc dot gnu dot org
2009-07-14 22:24 ` ian at airs dot com
` (15 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-14 20:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from manu at gcc dot gnu dot org 2009-07-14 20:56 -------
Joseph, could you comment on this?
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |joseph at codesourcery dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (2 preceding siblings ...)
2009-07-14 20:56 ` manu at gcc dot gnu dot org
@ 2009-07-14 22:24 ` ian at airs dot com
2009-07-14 22:30 ` [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type manu at gcc dot gnu dot org
` (14 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: ian at airs dot com @ 2009-07-14 22:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from ian at airs dot com 2009-07-14 22:23 -------
Manu, I agree that these warnings are in some sense technically correct but
they are not useful. They can't point to any actual bug. I guess would be
that if every input to the expression has the size of the target of the
expression, then the warning should be suppressed.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (3 preceding siblings ...)
2009-07-14 22:24 ` ian at airs dot com
@ 2009-07-14 22:30 ` manu at gcc dot gnu dot org
2009-07-15 7:50 ` photon at seznam dot cz
` (13 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-14 22:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2009-07-14 22:30 -------
Then, let's keep this around as an enhancement request.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-07-14 22:30:09
date| |
Summary|-Wconversion generates false|-Wconversion: do not warn
|warnings |for operands not larger than
| |target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (4 preceding siblings ...)
2009-07-14 22:30 ` [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type manu at gcc dot gnu dot org
@ 2009-07-15 7:50 ` photon at seznam dot cz
2009-07-15 7:55 ` photon at seznam dot cz
` (12 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-15 7:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from photon at seznam dot cz 2009-07-15 07:50 -------
(In reply to comment #1)
> Theses are not false warnings:
> c >>= 1;
>
> is really c = (int)c >> 1;
They are false warnings. The implicit conversion cannot alter the value.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (5 preceding siblings ...)
2009-07-15 7:50 ` photon at seznam dot cz
@ 2009-07-15 7:55 ` photon at seznam dot cz
2009-07-15 8:14 ` pinskia at gcc dot gnu dot org
` (11 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-15 7:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from photon at seznam dot cz 2009-07-15 07:54 -------
(In reply to comment #5)
> Then, let's keep this around as an enhancement request.
>
I think this is actually a bug as the specification of the warning is: Warn for
implicit conversions that may alter a value. This is not the case here.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (6 preceding siblings ...)
2009-07-15 7:55 ` photon at seznam dot cz
@ 2009-07-15 8:14 ` pinskia at gcc dot gnu dot org
2009-07-15 14:00 ` ian at airs dot com
` (10 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-15 8:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from pinskia at gcc dot gnu dot org 2009-07-15 08:13 -------
For:
c += (char) 1;
The value can change as you have a wrapping if c is CHAR_MAX.
Likewise with:
c += c2;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (7 preceding siblings ...)
2009-07-15 8:14 ` pinskia at gcc dot gnu dot org
@ 2009-07-15 14:00 ` ian at airs dot com
2009-07-15 14:15 ` joseph at codesourcery dot com
` (9 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: ian at airs dot com @ 2009-07-15 14:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from ian at airs dot com 2009-07-15 14:00 -------
Sure, it can wrap, but -Wconversion is not for wrapping warnings.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (8 preceding siblings ...)
2009-07-15 14:00 ` ian at airs dot com
@ 2009-07-15 14:15 ` joseph at codesourcery dot com
2009-07-15 16:56 ` photon at seznam dot cz
` (8 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: joseph at codesourcery dot com @ 2009-07-15 14:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from joseph at codesourcery dot com 2009-07-15 14:15 -------
Subject: Re: -Wconversion: do not warn for operands not larger
than target type
On Wed, 15 Jul 2009, ian at airs dot com wrote:
> Sure, it can wrap, but -Wconversion is not for wrapping warnings.
It's for warnings about implicit conversions changing a value; the
arithmetic, in a wider type (deliberately or otherwise), does not wrap,
but the value gets changed by the implicit conversion back to char. If
the user had explicit casts to int in their arithmetic, there could be no
doubt that the warning is appropriate.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (9 preceding siblings ...)
2009-07-15 14:15 ` joseph at codesourcery dot com
@ 2009-07-15 16:56 ` photon at seznam dot cz
2009-07-15 16:58 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-15 16:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from photon at seznam dot cz 2009-07-15 16:55 -------
(In reply to comment #8)
> For:
>
> c += (char) 1;
>
> The value can change as you have a wrapping if c is CHAR_MAX.
>
> Likewise with:
> c += c2;
>
The value cannot change even if an overflow occurs.
{
unsigned char c = 0xff;
c += 1;
// c is 0 here
c = 0xff;
c = (unsigned int)c + 1;
// c is 0 here
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (10 preceding siblings ...)
2009-07-15 16:56 ` photon at seznam dot cz
@ 2009-07-15 16:58 ` pinskia at gcc dot gnu dot org
2009-07-15 17:00 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-15 16:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from pinskia at gcc dot gnu dot org 2009-07-15 16:58 -------
Except it does alter its value from 0x100 to 0x00 :).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (11 preceding siblings ...)
2009-07-15 16:58 ` pinskia at gcc dot gnu dot org
@ 2009-07-15 17:00 ` pinskia at gcc dot gnu dot org
2009-07-15 18:24 ` photon at seznam dot cz
` (5 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-15 17:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #13 from pinskia at gcc dot gnu dot org 2009-07-15 17:00 -------
Or rather from SCHAR_MAX + 1 to SCHAR_MIN :). Since it is 0x7F + 1 ==
(int)0x80. So we have a negative value now from a positive value.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (12 preceding siblings ...)
2009-07-15 17:00 ` pinskia at gcc dot gnu dot org
@ 2009-07-15 18:24 ` photon at seznam dot cz
2009-07-16 7:07 ` [Bug c++/40752] -Wconversion generates false warnings " photon at seznam dot cz
` (4 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-15 18:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #14 from photon at seznam dot cz 2009-07-15 18:24 -------
(In reply to comment #13)
> Or rather from SCHAR_MAX + 1 to SCHAR_MIN :). Since it is 0x7F + 1 ==
> (int)0x80. So we have a negative value now from a positive value.
>
This occurs regardless of the implicit conversion. The implicit conversion
cannot alter the result. Therefore, the warning is false in this case too.
{
char c = 0x7f;
++c;
// c is 0x80 here
c = 0x7f;
c = (int)c + 1;
// c is 0x80 here
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (13 preceding siblings ...)
2009-07-15 18:24 ` photon at seznam dot cz
@ 2009-07-16 7:07 ` photon at seznam dot cz
2009-07-23 15:35 ` manu at gcc dot gnu dot org
` (3 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2009-07-16 7:07 UTC (permalink / raw)
To: gcc-bugs
--
photon at seznam dot cz changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|enhancement |normal
Summary|-Wconversion: do not warn |-Wconversion generates false
|for operands not larger than|warnings for operands not
|target type |larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (14 preceding siblings ...)
2009-07-16 7:07 ` [Bug c++/40752] -Wconversion generates false warnings " photon at seznam dot cz
@ 2009-07-23 15:35 ` manu at gcc dot gnu dot org
2009-09-05 14:05 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-23 15:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #15 from manu at gcc dot gnu dot org 2009-07-23 15:35 -------
Patch: http://gcc.gnu.org/ml/gcc-patches/2009-07/msg01179.html
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2009-
| |07/msg01179.html
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (15 preceding siblings ...)
2009-07-23 15:35 ` manu at gcc dot gnu dot org
@ 2009-09-05 14:05 ` manu at gcc dot gnu dot org
2010-06-11 20:22 ` manu at gcc dot gnu dot org
2010-06-12 16:46 ` photon at seznam dot cz
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-09-05 14:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #16 from manu at gcc dot gnu dot org 2009-09-05 14:05 -------
*** Bug 41274 has been marked as a duplicate of this bug. ***
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ashaduri at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (16 preceding siblings ...)
2009-09-05 14:05 ` manu at gcc dot gnu dot org
@ 2010-06-11 20:22 ` manu at gcc dot gnu dot org
2010-06-12 16:46 ` photon at seznam dot cz
18 siblings, 0 replies; 20+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-06-11 20:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #17 from manu at gcc dot gnu dot org 2010-06-11 20:22 -------
The patch was rejected but it may be accepted by using a new -Wno-* option to
disable these warnings. Perhaps -Wno-conversion-after-promotion?
Suggestions are welcome.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
` (17 preceding siblings ...)
2010-06-11 20:22 ` manu at gcc dot gnu dot org
@ 2010-06-12 16:46 ` photon at seznam dot cz
18 siblings, 0 replies; 20+ messages in thread
From: photon at seznam dot cz @ 2010-06-12 16:46 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 540 bytes --]
------- Comment #18 from photon at seznam dot cz 2010-06-12 16:46 -------
(In reply to comment #17)
> The patch was rejected but it may be accepted by using a new -Wno-* option to
> disable these warnings. Perhaps -Wno-conversion-after-promotion?
>
> Suggestions are welcome.
>
-Wconversion should be fixed to work as specified. No warning should be
generated for the following code:
char c = 2;
// warning: conversion to char from int may alter its value
c >>= 1;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2010-06-12 16:46 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-14 19:17 [Bug c++/40752] New: -Wconversion generates false warnings photon at seznam dot cz
2009-07-14 19:21 ` [Bug c++/40752] " pinskia at gcc dot gnu dot org
2009-07-14 20:56 ` manu at gcc dot gnu dot org
2009-07-14 20:56 ` manu at gcc dot gnu dot org
2009-07-14 22:24 ` ian at airs dot com
2009-07-14 22:30 ` [Bug c++/40752] -Wconversion: do not warn for operands not larger than target type manu at gcc dot gnu dot org
2009-07-15 7:50 ` photon at seznam dot cz
2009-07-15 7:55 ` photon at seznam dot cz
2009-07-15 8:14 ` pinskia at gcc dot gnu dot org
2009-07-15 14:00 ` ian at airs dot com
2009-07-15 14:15 ` joseph at codesourcery dot com
2009-07-15 16:56 ` photon at seznam dot cz
2009-07-15 16:58 ` pinskia at gcc dot gnu dot org
2009-07-15 17:00 ` pinskia at gcc dot gnu dot org
2009-07-15 18:24 ` photon at seznam dot cz
2009-07-16 7:07 ` [Bug c++/40752] -Wconversion generates false warnings " photon at seznam dot cz
2009-07-23 15:35 ` manu at gcc dot gnu dot org
2009-09-05 14:05 ` manu at gcc dot gnu dot org
2010-06-11 20:22 ` manu at gcc dot gnu dot org
2010-06-12 16:46 ` photon at seznam dot cz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).