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

            Bug ID: 59976
           Summary: Spurious warning on converting const int variable to
                    unsigned long
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

I define a static global variable "g" of type "const int", with a value 0. When
assigning it to a variable of type unsigned long, Gcc emits a warning on the
signedness conversion. As "g" is not modifiable and equivalent to "0", there is
no signedness conversion actually. 




$: cat s.c
static const int g = 0;
void fn() {
  unsigned long l = g;
}
$: gcc-trunk -c -Wconversion s.c
s.c: In function ‘fn’:
s.c:3:3: warning: conversion to ‘long unsigned int’ from ‘int’ may change the
sign of the result [-Wsign-conversion]
   unsigned long l = g;
   ^
$: gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/chengniansun/tools/gcc-trunk-binaries/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c,c++
--disable-multilib --prefix=/home/chengniansun/tools/gcc-trunk-binaries :
(reconfigured) ../gcc-trunk/configure --enable-languages=c,c++
--disable-multilib --prefix=/home/chengniansun/tools/gcc-trunk-binaries
Thread model: posix
gcc version 4.9.0 20140127 (experimental) (GCC)
$:
$: clang-trunk -c -Wconversion s.c
$:

Reply via email to