public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49626] New: Explicit conversion skipped when followed by conversion to a wider type
@ 2011-07-04 11:36 fn42551 at fmi dot uni-sofia.bg
  2011-07-04 11:38 ` [Bug c++/49626] " fn42551 at fmi dot uni-sofia.bg
  2011-07-12 13:57 ` [Bug c/49626] " jason at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: fn42551 at fmi dot uni-sofia.bg @ 2011-07-04 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Explicit conversion skipped when followed by
                    conversion to a wider type
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fn42551@fmi.uni-sofia.bg


Hello.

I think I've encountered a case regarding conversions between integral types. 
It is demonstrated by the attached file which, when compiled with
"-Wsign-conversion", makes g++ produce the following warning:

sign-conversion-bug.cpp: In function 'long unsigned int f()':
sign-conversion-bug.cpp:5: warning: conversion to 'long unsigned int' from
'short int' may change the sign of the result

The source code requests two conversions:
1. an explicit one from 'short int' to 'unsigned int';
2. an implicit one from 'unsigned int' to 'unsigned long int'.

However, g++ only seems to attempt a single conversion -- an implicit one from
'short int' to 'unsigned long int'.  Is this the intended behaviour?


Output from "g++ -v":

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1) 


I also tested with gcc versions 4.3.6 and 4.4.6, and I got the same results.


Regards,
Angel Tsankov


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

* [Bug c++/49626] Explicit conversion skipped when followed by conversion to a wider type
  2011-07-04 11:36 [Bug c++/49626] New: Explicit conversion skipped when followed by conversion to a wider type fn42551 at fmi dot uni-sofia.bg
@ 2011-07-04 11:38 ` fn42551 at fmi dot uni-sofia.bg
  2011-07-12 13:57 ` [Bug c/49626] " jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: fn42551 at fmi dot uni-sofia.bg @ 2011-07-04 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Angel Tsankov <fn42551 at fmi dot uni-sofia.bg> 2011-07-04 11:37:47 UTC ---
Created attachment 24671
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24671
Demonstrates the case


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

* [Bug c/49626] Explicit conversion skipped when followed by conversion to a wider type
  2011-07-04 11:36 [Bug c++/49626] New: Explicit conversion skipped when followed by conversion to a wider type fn42551 at fmi dot uni-sofia.bg
  2011-07-04 11:38 ` [Bug c++/49626] " fn42551 at fmi dot uni-sofia.bg
@ 2011-07-12 13:57 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2011-07-12 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.07.12 13:56:39
                 CC|                            |jason at gcc dot gnu.org
          Component|c++                         |c
     Ever Confirmed|0                           |1

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-07-12 13:56:39 UTC ---
This does seem like a bug, since the documentation says "An explicit cast
silences the warning."  This bug also affects the C front end, so I'm changing
the category to C.

unsigned long f()
{
  short sh;
  return (unsigned int)sh;
}


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

end of thread, other threads:[~2011-07-12 13:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-04 11:36 [Bug c++/49626] New: Explicit conversion skipped when followed by conversion to a wider type fn42551 at fmi dot uni-sofia.bg
2011-07-04 11:38 ` [Bug c++/49626] " fn42551 at fmi dot uni-sofia.bg
2011-07-12 13:57 ` [Bug c/49626] " jason at gcc dot gnu.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).