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]

[Bug c/59976] Spurious warning on converting const int variable to unsigned long (Also inconsistency between O0 and O1)


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-04-15
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.9.3, 5.3.0, 6.0

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  The warning is also inconsistent between C and C++ modes, likely
because G++ treats the constant b as a constant expression regardless of
optimization while GCC treats it as an ordinary variable with an unknown value
(i.e., it doesn't fold its value without optimization).

This would be solved by making GCC more aggressive about constant folding and
treating more expressions as constant expressions, as requested for example in
bug 69960.  It might be worth to collect the kinds of expressions that could be
considered constant so that they can all be considered at the same time if/when
someone decides to put together a patch for one (or more) of these bugs.

$ cat v.c && gcc -S -Wconversion -xc v.c
unsigned g;
void fn1() {
  int a;
  const unsigned char b = 0;
  a = b & g;
}
v.c: In function âfn1â:
v.c:5:7: warning: conversion to âintâ from âunsigned intâ may change the sign
of the result [-Wsign-conversion]
   a = b & g;
       ^

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