This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR 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
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Manuel López-Ibáñez <lopezibanez at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 20 Dec 2008 00:15:29 +0100
- Subject: Re: PR 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
- References: <6c33472e0810250750y33c10265g3195e8613de1b1fc@mail.gmail.com> <20081025162735.GM14706@tyan-ft48-01.lab.bos.redhat.com> <6c33472e0811041414l57b4b98ibb84350dcf60117f@mail.gmail.com> <494C2488.7000002@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Dec 19, 2008 at 05:47:36PM -0500, Jason Merrill wrote:
> I agree that we don't want to warn for this code, but I think the right
> place to fix it is in warn_about_parentheses; your patch will also
> disable the parenthesis warnings for overloaded comparison ops, which we
> don't want, since precedence is the same regardless of the return type.
warn_about_parentheses isn't passed the whole expr though, so it can't check
its type.
Manu's patch just stopped calling warn_about_parentheses for (non-bool
returning overloaded) comparison other than ==/!=, but when code
has tcc_comparison class other than EQ_EXPR/NE_EXPR,
default:
if (TREE_CODE_CLASS (code) == tcc_comparison
&& ((TREE_CODE_CLASS (code_left) == tcc_comparison
&& code_left != NE_EXPR && code_left != EQ_EXPR)
|| (TREE_CODE_CLASS (code_right) == tcc_comparison
&& code_right != NE_EXPR && code_right != EQ_EXPR)))
warning (OPT_Wparentheses, "comparisons like %<X<=Y<=Z%> do not "
"have their mathematical meaning");
is the only thing warn_about_parentheses warns about.
We already have a precedent in build_x_binary_op for avoiding
warn_about_parentheses call in other situations, in particular about
obj << x + y.
Jakub