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: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 25 Oct 2008 18:27:35 +0200
- 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>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Sat, Oct 25, 2008 at 04:50:59PM +0200, Manuel López-Ibáñez wrote:
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
> --enable-languages=all,obj-c++ --enable-decimal-float.
>
> OK for trunk and 4.3?
>
> 2008-10-25 Manuel López-Ibáñez <manu@gcc.gnu.org>
>
> PR c++/36921
> cp/
> * typeck.c (build_x_binary_op): Do not warn for overloaded
> comparison operators that do not return boolean.
> testsuite/
> * g++.dg/warn/pr36921.C: New.
Are you sure we don't want to warn even about the:
if (code == EQ_EXPR || code == NE_EXPR)
{
if (TREE_CODE_CLASS (code_left) == tcc_comparison
|| TREE_CODE_CLASS (code_right) == tcc_comparison)
warning (OPT_Wparentheses,
"suggest parentheses around comparison in operand of %s",
code == EQ_EXPR ? "==" : "!=");
}
case if EQ_EXPR or NE_EXPR don't return boolean?
I'd say you want:
> + /* Do not warn about overloaded comparison operator that does
> + not return boolean. */
> + && (TREE_CODE_CLASS (code) != tcc_comparison
> + || TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE))
+ /* Do not warn about overloaded comparison operator that does
+ not return boolean. */
+ && (TREE_CODE_CLASS (code) != tcc_comparison
+ || code == EQ_EXPR
+ || code == NE_EXPR
+ || TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE))
> warn_about_parentheses (code, arg1_code, orig_arg1, arg2_code, orig_arg2);
Jakub