c++/1056: spurious warning on implicit conversion followed by promotion and comparison

Wolfgang Bangerth bangerth@ticam.utexas.edu
Sun Nov 10 13:12:00 GMT 2002


This report is about this code:
---------------------------------------
struct X {
  operator unsigned short () const;
};

int main() {
  X s;
  unsigned long l;

  if (l == s);
  if (s == l);

  return 0;
}
------------------------------
and the following warnings:
tmp/g> /home/bangerth/bin/gcc-3.3x-pre/bin/gcc -W -Wall -c x.cc
x.cc: In function `int main()':
x.cc:9: warning: comparison between signed and unsigned integer expressions
x.cc:10: warning: comparison between signed and unsigned integer expressions

I had initially thought that this may be due to argument promotion to a 
signed type from the unsigned short the conversion operator returns, but 
then the same should happen when we define "s" as an unsigned short right 
from the start. However, this makes the warning go away. So I don't 
know...

W.

-------------------------------------------------------------------------
Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth




More information about the Gcc-bugs mailing list