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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ 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; 28+ 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] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2014-02-10  1:14 ` chengniansun at gmail dot com
@ 2014-09-16 21:07 ` hariharan.gcc at gmail dot com
  7 siblings, 0 replies; 28+ messages in thread
From: hariharan.gcc at gmail dot com @ 2014-09-16 21:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

hariharan.gcc at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hariharan.gcc at gmail dot com

--- Comment #27 from hariharan.gcc at gmail dot com ---
I encountered a similar problem with -Wconversion. This option is useless if it
would warn for cases like

short int i;
i += 5;

I concede Andrew's point about this being technically a place to warn, but in
practice, i would like for it to warn only when the target is a "smaller" than
any of the inputs.


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2012-06-20 14:59 ` dichlofos-mv at yandex dot ru
@ 2014-02-10  1:14 ` chengniansun at gmail dot com
  2014-09-16 21:07 ` hariharan.gcc at gmail dot com
  7 siblings, 0 replies; 28+ messages in thread
From: chengniansun at gmail dot com @ 2014-02-10  1:14 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 2897 bytes --]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

--- Comment #25 from Chengnian Sun <chengniansun at gmail dot com> ---
Today I encountered a similar case as follows. The conversion warning by gcc is
not true as right-shifting an unsigned short decreases the value. 

BTW clang does not emit warnings for this code snippet. 


$: cat s1.c
unsigned short fn(unsigned short a, int right) {
  return a >> right;
}
$: gcc-trunk -c -Wconversion s1.c
s1.c: In function ‘fn’:
s1.c:2:3: warning: conversion to ‘short unsigned int’ from ‘int’ may alter its
value [-Wconversion]
   return a >> right;
   ^
$: clang-trunk -c -Wconversion s1.c
$:
>From gcc-bugs-return-443154-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Feb 10 01:28:47 2014
Return-Path: <gcc-bugs-return-443154-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15230 invoked by alias); 10 Feb 2014 01:28:47 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 15198 invoked by uid 48); 10 Feb 2014 01:28:43 -0000
From: "dartmetrash at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/60113] Internal compiler error
Date: Mon, 10 Feb 2014 01:28:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.6.3
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: dartmetrash at gmail dot com
X-Bugzilla-Status: WAITING
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-60113-4-qIPcKsoEnk@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60113-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60113-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-02/txt/msg00911.txt.bz2
Content-length: 461

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`113

--- Comment #2 from lmat <dartmetrash at gmail dot com> ---
Created attachment 32090
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id2090&actioníit
Bug report including command line output.

My apologies! I was quite sure I had attached it, but I see quite plainly that
I had failed! It appears that my upload was too big. I've divided it up using

split --lines 35000 ...

which creates three files.


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2012-05-05 16:05 ` manu at gcc dot gnu.org
@ 2012-06-20 14:59 ` dichlofos-mv at yandex dot ru
  2014-02-10  1:14 ` chengniansun at gmail dot com
  2014-09-16 21:07 ` hariharan.gcc at gmail dot com
  7 siblings, 0 replies; 28+ messages in thread
From: dichlofos-mv at yandex dot ru @ 2012-06-20 14:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

Mikhail Veltishchev <dichlofos-mv at yandex dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dichlofos-mv at yandex dot
                   |                            |ru

--- Comment #24 from Mikhail Veltishchev <dichlofos-mv at yandex dot ru> 2012-06-20 14:57:31 UTC ---
Well, please fix this. My cases are instructions like
unsigned short x = 100;
unsigned short y = 200;
// gives a warning
x += y;


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2012-05-05 15:31 ` wessjunk at gmail dot com
@ 2012-05-05 16:05 ` manu at gcc dot gnu.org
  2012-06-20 14:59 ` dichlofos-mv at yandex dot ru
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-05 16:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

--- Comment #23 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-05 15:30:06 UTC ---
(In reply to comment #22)
> If someone really thinks there should be a warning for this behavior, how about
> adding a separate
> -Wchar-arithmetic
> warning which warns on all char arithmetic and see how much people use it.

I think adding a new option Wconversion-after-promotion that covers all cases
where the conversion occurs to the same type that was originally promoted from
would be the most appropriate. I have a feeling that it should not be hard to
implement, but I am not sure how, and I have many other things I would like to
do first. So, please David, Wes, photon, give it a try. The code is in
c-family/c-common.c (conversion_warning).


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2012-03-24 21:40 ` DeusExSophismata at gmail dot com
@ 2012-05-05 15:31 ` wessjunk at gmail dot com
  2012-05-05 16:05 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: wessjunk at gmail dot com @ 2012-05-05 15:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

Wes <wessjunk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wessjunk at gmail dot com

--- Comment #22 from Wes <wessjunk at gmail dot com> 2012-05-05 15:09:22 UTC ---
I agree with David.  My code has many instances of things like
a+=2
where a is a char and this makes -Wconversion useless to me.

It's too bad, since it would really be helpful as I am in the process of
changing some data types in the code.

If someone really thinks there should be a warning for this behavior, how about
adding a separate
-Wchar-arithmetic
warning which warns on all char arithmetic and see how much people use it.


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
  2011-09-25 21:55 ` manu at gcc dot gnu.org
  2012-03-24 20:21 ` manu at gcc dot gnu.org
@ 2012-03-24 21:40 ` DeusExSophismata at gmail dot com
  2012-05-05 15:31 ` wessjunk at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: DeusExSophismata at gmail dot com @ 2012-03-24 21:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

--- Comment #21 from David Stone <DeusExSophismata at gmail dot com> 2012-03-24 21:25:08 UTC ---
Why was this patch rejected, and is there a way to improve it so that obviously
safe cases (such as PR52703) are not warned about without having to specify a
'-Wno-' option?

Yes, according to the standard (C++03 5/9), calculations done on variables
smaller than int are first promoted to int, then the calculation is done, then
the value is converted back to the target size. However, C++03 1.8/3, the
"as-if rule", states that it the program can't tell the difference, you can do
whatever you want (see my answer to a similar question on Stack Overflow here:
http://stackoverflow.com/questions/5563000/implicit-type-conversion-rules-in-c-operators/8935697#8935697).

The C++ standard does not require a diagnostic for this, and the apparent
behavior is identical. Therefore, there can be no appeals to the C++ standard
on the behavior of the warning.

Because this is a purely option warning for which gcc defines the rules, we
should define it to be useful. If gcc can prove that all of the values are
greater than 0 (for instance, if all of the values are unsigned prior to
implicit promotion or are positive integral constant expressions), then there
is no possibility of having a negative value. Thanks to signed integer overflow
being undefined, there is no risk of creating a negative value that way,
either. Therefore, we should not warn. Having to manually say "Turn off stuff
that no one could ever possibly want to see" seems like a sure way to make this
warning useless.


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
  2011-09-25 21:55 ` manu at gcc dot gnu.org
@ 2012-03-24 20:21 ` manu at gcc dot gnu.org
  2012-03-24 21:40 ` DeusExSophismata at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: manu at gcc dot gnu.org @ 2012-03-24 20:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |DeusExSophismata at gmail
                   |                            |dot com

--- Comment #20 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-03-24 19:27:54 UTC ---
*** Bug 52703 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
       [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-25 21:55 ` manu at gcc dot gnu.org
  2012-03-24 20:21 ` manu at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: manu at gcc dot gnu.org @ 2011-09-25 21:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebrahim at mohammadi dot ir

--- Comment #19 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-09-25 21:12:33 UTC ---
*** Bug 50519 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2014-09-16 21:07 UTC | newest]

Thread overview: 28+ 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
     [not found] <bug-40752-4@http.gcc.gnu.org/bugzilla/>
2011-09-25 21:55 ` manu at gcc dot gnu.org
2012-03-24 20:21 ` manu at gcc dot gnu.org
2012-03-24 21:40 ` DeusExSophismata at gmail dot com
2012-05-05 15:31 ` wessjunk at gmail dot com
2012-05-05 16:05 ` manu at gcc dot gnu.org
2012-06-20 14:59 ` dichlofos-mv at yandex dot ru
2014-02-10  1:14 ` chengniansun at gmail dot com
2014-09-16 21:07 ` hariharan.gcc at gmail dot com

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).