[Bug c++/36921] [4.3/4.4 Regression] warning "comparison does not have mathematical meaning" is not correct for overloaded operators that do not return boolean

deba at inf dot elte dot hu gcc-bugzilla@gcc.gnu.org
Wed Dec 3 19:27:00 GMT 2008



------- Comment #9 from deba at inf dot elte dot hu  2008-12-03 19:26 -------
(In reply to comment #8)
> I'm not convinced that we shouldn't warn in these cases.  Yes, there are cases
> where people overload the operators in ways that make normal precedence
> irrelevant.  But, there are also cases where people define boolean-like objects
> that are not themselves "bool".
> 
If the user-defined boolean-like object can be compared with other types, then
the user had to write such a comparison operator, therefore the user declared
that the boolean-like type is comparable with the other type. So this case
could not be a problem.

However, in my point of view, the proposed patch is not surely the best
solution. The C++ defined the bool, which could solve the (a < b < c) problem.
But unfortunately, as a shortcoming of the backward compatibility with C, the
bool type is convertible to numeric types, which is a quite wrong pitfall. I
think, instead of the current patch, the implicit conversion of a bool to
numeric value should be warned in C++.


-- 


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



More information about the Gcc-bugs mailing list