Bug 8419 - Erroneous warning: left shift count >= width of type
Summary: Erroneous warning: left shift count >= width of type
Status: RESOLVED DUPLICATE of bug 4210
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Wolfgang Bangerth
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-31 20:46 UTC by carlo
Modified: 2003-06-12 00:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description carlo 2002-10-31 20:46:01 UTC
Compiler gives a warning about a shift width
for code that is never executed.  This is highly
annoying because there is no work around and I
always use -Werror.

I reported this as C++ front-end, because I think
that this can only be a problem when the shift is
a template parameter 'constant'; otherwise you can
avoid the warning by simply not including the code
that is never executed.

Release:
gcc-3.2

Environment:
i686-gnu-linux

How-To-Repeat:
Compile the following:

void f()
{
  static int const s = 32;

  unsigned int a = 0x12345678;
  if (s >= 32)
    a = 0;
  else          // Now s is garanteed less than 32!
    a <<= s;
}


Or, more practical, compile this:

template<unsigned int shift>
  unsigned int f(unsigned int a)
  {
    if (shift >= 32)
      a = 0;
    else                // Now s is garanteed less than 32!
      a <<= shift;
  }

void g()
{
  f<32>(0x12345678);
}


> g++-3.2 -v -c troep.cc
Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: /usr/src/gcc/gcc-3.2/configure --prefix=/usr/local/gcc-3.2 --enable-shared --with-gnu-as --with-gnu-ld --enable-languages=c++ --enable-debug --enable-threads
Thread model: posix
gcc version 3.2
 /usr/local/gcc-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ troep.cc -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -quiet -dumpbase troep.cc -version -o /tmp/ccqu1OxB.s
GNU CPP version 3.2 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2 (i686-pc-linux-gnu)
        compiled by GNU C version 3.2.
ignoring nonexistent directory "/usr/local/gcc-3.2/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-3.2/include/c++/3.2
 /usr/local/gcc-3.2/include/c++/3.2/i686-pc-linux-gnu
 /usr/local/gcc-3.2/include/c++/3.2/backward
 /usr/local/include
 /usr/local/gcc-3.2/include
 /usr/local/gcc-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/include
 /usr/include
End of search list.
troep.cc: In function `unsigned int f(unsigned int) [with unsigned int shift =
   32]':
troep.cc:12:   instantiated from here
troep.cc:7: warning: left shift count >= width of type
 as -V -Qy -o troep.o /tmp/ccqu1OxB.s
GNU assembler version 2.12.90.0.15 (i386-redhat-linux) using BFD version 2.12.90.0.15 20020717
Comment 1 Wolfgang Bangerth 2002-11-06 14:07:22 UTC
*** This bug has been marked as a duplicate of 4210 ***