This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/8419: Erroneous warning: left shift count >= width of type


>Number:         8419
>Category:       c++
>Synopsis:       Erroneous warning: left shift count >= width of type
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 31 20:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     carlo@alinoe.com
>Release:        gcc-3.2
>Organization:
>Environment:
i686-gnu-linux
>Description:
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.

>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
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]