public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26292]  New: Bad code in unsigned shifts
@ 2006-02-14 21:44 igodard at pacbell dot net
  2006-02-14 21:51 ` [Bug c++/26292] " igodard at pacbell dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: igodard at pacbell dot net @ 2006-02-14 21:44 UTC (permalink / raw)
  To: gcc-bugs

In the code:
#include <iostream>
typedef unsigned int uint;
typedef long long int ll;
int main() {
    int i = 0;
    ll a = uint(1);
    ll b = (uint(1) << (32 - i));
    ll c = ((uint(1) << (32 - i)) - 1 );
    ll d = (((uint(1) << (32 - i)) - 1) << 0);
    std::cerr << std::hex <<a << ":" << b << ":" << c << ":" << d << "\n";
    }

the compiler:
~/ootbc/common$ g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.2/configure --prefix=/home/ivan/gcc
--enable-languages=c,c++
Thread model: posix
gcc version 4.0.2

gives you:

~/ootbc/common$ a.out
1:1:0:0


whereas the correct result would be "1:0:ffffffff:ffffffff".

Interestingly, on Cygwin the compiler:
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr
--exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs --without-x
--enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter
--disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm
--disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization
--enable-libstdcxx-debug : (reconfigured) 
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)


gives you:
~/ootbc/common: a.exe
1:1:0:7fffffff


Ivan


-- 
           Summary: Bad code in unsigned shifts
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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


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

end of thread, other threads:[~2006-02-14 22:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-14 21:44 [Bug c++/26292] New: Bad code in unsigned shifts igodard at pacbell dot net
2006-02-14 21:51 ` [Bug c++/26292] " igodard at pacbell dot net
2006-02-14 21:57 ` pinskia at gcc dot gnu dot org
2006-02-14 21:59 ` pinskia at gcc dot gnu dot org
2006-02-14 22:18 ` igodard at pacbell dot net
2006-02-14 22:21 ` pinskia 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).