public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* 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
@ 2008-10-25 16:52 Manuel López-Ibáñez
  2008-10-25 17:10 ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Manuel López-Ibáñez @ 2008-10-25 16:52 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix-pr36921.diff --]
[-- Type: text/x-diff; name=fix-pr36921.diff, Size: 1463 bytes --]

Index: gcc/testsuite/g++.dg/warn/pr36921.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr36921.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr36921.C	(revision 0)
@@ -0,0 +1,13 @@
+/* PR 36921: comparison operator can be overloaded. Do not emit
+   warnings in such case.
+ { dg-do compile }
+ { dg-options "-Wparentheses" }
+*/
+struct A {};
+A operator<(A, A) { return A(); }
+
+int main() {
+  A() < A() < A(); // should not emit warning
+  1 < 2 < 3; // { dg-warning "mathematical meaning" "parentheses" }
+  return 0;
+}
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 141350)
+++ gcc/cp/typeck.c	(working copy)
@@ -3155,11 +3155,15 @@ build_x_binary_op (enum tree_code code, 
   if (warn_parentheses
       && !processing_template_decl
       && !error_operand_p (arg1)
       && !error_operand_p (arg2)
       && (code != LSHIFT_EXPR
-	  || !CLASS_TYPE_P (TREE_TYPE (arg1))))
+	  || !CLASS_TYPE_P (TREE_TYPE (arg1)))
+      /* 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))
     warn_about_parentheses (code, arg1_code, orig_arg1, arg2_code, orig_arg2);
 
   if (processing_template_decl && expr != error_mark_node)
     return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-12-20 17:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-25 16:52 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 Manuel López-Ibáñez
2008-10-25 17:10 ` Jakub Jelinek
2008-11-04 22:15   ` Manuel López-Ibáñez
2008-12-03 17:49     ` Mark Mitchell
2008-12-19 23:32     ` Jason Merrill
2008-12-19 23:38       ` Jakub Jelinek
2008-12-19 23:50         ` Jason Merrill
2008-12-20  0:13           ` Mark Mitchell
2008-12-20  0:17           ` Jakub Jelinek
2008-12-20 12:43             ` Jakub Jelinek
2008-12-20 13:38             ` Jakub Jelinek
2008-12-20 22:33               ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).