This is the mail archive of the gcc@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]

Extra warning


Hi,

gcc-3.1 doesn't seem to warn for the following code (even with
-Wconversion -W -Wall).

  unsigned a;
  double c;
  a = 10;
  c = -10 - a;

Which makes c 4294967276.00 rather than -20. It also doesn't warn for:

  unsigned a;
  int b;
  double c;
  a = 10;
  b = -10;
  c = b - a;

(which of course would be harder to warn for).

Am I missing the appropriate warning option? Would it be sensible/possible
to warn for the promotion of obvious negative integers to unsigned?

Perhaps int-unsigned should have a warning. (int+unsigned usually works if
int is -ve, but probably not according to the standard!).

Thanks

Jeremy

-- 
Jeremy Sanders <jss@ast.cam.ac.uk>   http://www-xray.ast.cam.ac.uk/~jss/
X-Ray Group, Institute of Astronomy, University of Cambridge, UK.
Public Key Server PGP Key ID: E1AAE053


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