[Bug c/12963] Wrong and misleading warning encourages writing non-portable code

pcarlini at suse dot de gcc-bugzilla@gcc.gnu.org
Wed Jan 25 12:21:00 GMT 2006



------- Comment #20 from pcarlini at suse dot de  2006-01-25 12:20 -------
(In reply to comment #19)
> Just a small update.  On one of our projects we have now thousands of warnings
> on the test "x < 0" for the function below, when Type is instantiated to an
> unsigned integral type:
> 
> template <typename Type>
> inline Result
> sgn_generic(const Type& x) {
>   if (x < 0)
>     return V_LT;
>   if (x > 0)
>     return V_GT;
>   return V_EQ;
> }

A side remark, about a weird workaround I had to use in the past in the library
(yes the problem is real, I agree, not sure about the best solution, however).
Would boil down to something like (mosulo stupid typos ;)

  if (x > 0)
    return V_GT;
  else if (x) 
    return V_LT;
  return V_EQ;

Seems correct to me and doesn't incur in any warning.


-- 


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



More information about the Gcc-bugs mailing list