This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]