This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/12963] Wrong and misleading warning encourages writing non-portable code
- From: "pcarlini at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Jan 2006 12:21:01 -0000
- Subject: [Bug c/12963] Wrong and misleading warning encourages writing non-portable code
- References: <bug-12963-1710@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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