public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26298]  New: no warning for implicit type conversion
@ 2006-02-15  9:10 m dot becker at spider-software dot net
  2006-02-15 10:36 ` [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion rguenth at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: m dot becker at spider-software dot net @ 2006-02-15  9:10 UTC (permalink / raw)
  To: gcc-bugs

The following code gives two different results without any warning:

#include <stdio.h>

void toInt(int i)
{
  fprintf(stderr, "i = %d\n", i);
}

void toLongLong(long long L)
{
  fprintf(stderr, "L = %lld\n", L);
}

int main()
{
  toInt(-sizeof(int));
  toLongLong(-sizeof(int));

  return 0;
}

There should at least be a warning.
This behaviour can be found on SUN and on Linux x86 with compiler versions
between 3.4.4 and 4.0.3 (prerelease).


-- 
           Summary: no warning for implicit type conversion
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: m dot becker at spider-software dot net


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
@ 2006-02-15 10:36 ` rguenth at gcc dot gnu dot org
  2006-09-16  1:38 ` lopezibanez at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-15 10:36 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-02-15 10:36 -------
With -Wconversion you get

t.c:5: warning: passing argument 1 of ‘toLongLong’ with different width due to
prototype

though -Wconversion is neither in -Wall nor -Wextra.  I see you filed against
C++, which doesn't warn here, but we have a bug for a similar case already.

Also the C diagnostic could be improved in the case of a widening sign
conversion,
because that is more likely an error than a non-widening sign conversion.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |26167
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2006-02-15 10:36:07
               date|                            |
            Summary|no warning for implicit type|-Wconversion fails to detect
                   |conversion                  |signedness change during
                   |                            |widening conversion


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
  2006-02-15 10:36 ` [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion rguenth at gcc dot gnu dot org
@ 2006-09-16  1:38 ` lopezibanez at gmail dot com
  2006-09-16 17:08 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: lopezibanez at gmail dot com @ 2006-09-16  1:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from lopezibanez at gmail dot com  2006-09-16 01:38 -------
Richard, could you tell which bug report do you mean?

The -Wconversion warnings does not apply to this case. Wconversion warns about
the effect of adding a prototype, not about sign conversions. 

Anyway, I still don't understand where is the bug. Unary minus applied to
unsigned (what typically is the type of sizeof()) gives:

" `2^n - i', where `n' is the number of bits in the
unsigned type." [1]

So actually -sizeof(int) is 4294967292 (assuming sizeof(int) is 4). This number
fits well in a signed long long. However, it doesn't fit in a signed int, and
thus, it wraps around and produces -4.

The -Wcoercion flag provided by the Wcoercion project [2] warns for the
wrap-around as:

pr26298.c:15: warning: coercion as 'int' alters 'unsigned int' constant value


[1] http://gcc.gnu.org/ml/gcc/1999-06n/msg00754.html
[2] http://gcc.gnu.org/wiki/Wcoercion


-- 

lopezibanez at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lopezibanez at gmail dot
                   |                            |com, rguenth at gcc dot gnu
                   |                            |dot org


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
  2006-02-15 10:36 ` [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion rguenth at gcc dot gnu dot org
  2006-09-16  1:38 ` lopezibanez at gmail dot com
@ 2006-09-16 17:08 ` rguenth at gcc dot gnu dot org
  2006-09-16 19:45 ` lopezibanez at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-09-16 17:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2006-09-16 17:08 -------
26167, the one I added in the dependencies


-- 


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
                   ` (2 preceding siblings ...)
  2006-09-16 17:08 ` rguenth at gcc dot gnu dot org
@ 2006-09-16 19:45 ` lopezibanez at gmail dot com
  2006-09-17 21:02 ` rguenth at gcc dot gnu dot org
  2006-10-16 15:37 ` mueller at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: lopezibanez at gmail dot com @ 2006-09-16 19:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from lopezibanez at gmail dot com  2006-09-16 19:45 -------
Richard,

and what is your opinion about the rest of my comment?


-- 


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
                   ` (3 preceding siblings ...)
  2006-09-16 19:45 ` lopezibanez at gmail dot com
@ 2006-09-17 21:02 ` rguenth at gcc dot gnu dot org
  2006-10-16 15:37 ` mueller at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-09-17 21:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2006-09-17 21:02 -------
Well, you are right.  This bug is a dup of the bug requesting -Wcoercion (if we
have such).


-- 


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


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

* [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion
  2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
                   ` (4 preceding siblings ...)
  2006-09-17 21:02 ` rguenth at gcc dot gnu dot org
@ 2006-10-16 15:37 ` mueller at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: mueller at gcc dot gnu dot org @ 2006-10-16 15:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mueller at gcc dot gnu dot org  2006-10-16 15:37 -------


*** This bug has been marked as a duplicate of 26167 ***


-- 

mueller at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2006-10-16 15:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-15  9:10 [Bug c++/26298] New: no warning for implicit type conversion m dot becker at spider-software dot net
2006-02-15 10:36 ` [Bug c++/26298] -Wconversion fails to detect signedness change during widening conversion rguenth at gcc dot gnu dot org
2006-09-16  1:38 ` lopezibanez at gmail dot com
2006-09-16 17:08 ` rguenth at gcc dot gnu dot org
2006-09-16 19:45 ` lopezibanez at gmail dot com
2006-09-17 21:02 ` rguenth at gcc dot gnu dot org
2006-10-16 15:37 ` mueller at gcc dot gnu dot org

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