[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#341345: gcc-4.0: Please warn on impossible && conditionals



Hi Justin,

see lower ...

Justin Pryzby wrote:
Package: gcc-4.0
Version: 4.0.2-4
Severity: wishlist
Tags: upstream

gcc will warn on something like

  char c;
  // ...
  if (c>256) {
  // warning: comparison is always false due to limited range of data type
  // ...
  }

Please consider also warning on things like:


I would imagine this below:


  if (0==c && 1==c)

isn't a good idea, because it would break symmetry with custom operator==() behaviour.

eg, if I did

class MySillyClass { ... };

inline bool operator==(MySillyClass const& a, int b)
{
   return (b == 0 || b == 1);
}


then:

char c;
if (c == 0 && c == 1)  // WARNING

MySillyClass d;
if (d == 0 && d == 1) // should NOT warn


then, if i did:

template <class T>
bool test(T x)
{
   return (x == 0 && x == 1);
}

test() would warn on some types and not others.  That would be annoying!


right?
thanks for the brain snack,
Paul



Reply to: