]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/36921 (warning "comparison does not have mathematical meaning" is not corre...
authorJakub Jelinek <jakub@redhat.com>
Sat, 20 Dec 2008 18:46:12 +0000 (19:46 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 20 Dec 2008 18:46:12 +0000 (19:46 +0100)
PR c++/36921
* c-common.c (warn_about_parentheses): Remove ARG_UNUSED from
arg_left.  Don't warn about X<=Y<=Z if comparison's type isn't
integral.

* g++.dg/warn/pr36921.C: New.

Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
From-SVN: r142849

gcc/c-common.c
gcc/cp/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr36921.C [new file with mode: 0644]

index e83b58e1d655e8dd10aace06e5348820f9d48d96..d08a25b96656e0730c61ced284d5f9f9aef2ef49 100644 (file)
@@ -8059,7 +8059,7 @@ warn_array_subscript_with_type_char (tree index)
 
 void
 warn_about_parentheses (enum tree_code code,
-                       enum tree_code code_left, tree ARG_UNUSED (arg_left),
+                       enum tree_code code_left, tree arg_left,
                        enum tree_code code_right, tree arg_right)
 {
   if (!warn_parentheses)
@@ -8169,9 +8169,11 @@ warn_about_parentheses (enum tree_code code,
     default:
       if (TREE_CODE_CLASS (code) == tcc_comparison
           && ((TREE_CODE_CLASS (code_left) == tcc_comparison
-               && code_left != NE_EXPR && code_left != EQ_EXPR)
+               && code_left != NE_EXPR && code_left != EQ_EXPR
+               && INTEGRAL_TYPE_P (TREE_TYPE (arg_left)))
               || (TREE_CODE_CLASS (code_right) == tcc_comparison
-                  && code_right != NE_EXPR && code_right != EQ_EXPR)))
+                  && code_right != NE_EXPR && code_right != EQ_EXPR
+                  && INTEGRAL_TYPE_P (TREE_TYPE (arg_right)))))
        warning (OPT_Wparentheses, "comparisons like %<X<=Y<=Z%> do not "
                 "have their mathematical meaning");
       return;
index ad0506a6985e33b824518240d9965f26f33e1904..19af86ccde6d55d7bff5e75b054b4500e18f1233 100644 (file)
@@ -1,3 +1,11 @@
+2008-12-20  Jakub Jelinek  <jakub@redhat.com>
+           Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/36921
+       * c-common.c (warn_about_parentheses): Remove ARG_UNUSED from
+       arg_left.  Don't warn about X<=Y<=Z if comparison's type isn't
+       integral.
+
 2008-12-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/38577
index fd9e53766cd6387e67757b4962f4096c698d2d4f..11feb22bd969f39612b8ea303cabdd56abea98ec 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-20  Jakub Jelinek  <jakub@redhat.com>
+           Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/36921
+       * g++.dg/warn/pr36921.C: New.
+
 2008-12-19  Joel Sherrill <joel.sherrill@oarcorp.com>
 
        * lib/target-supports.exp: Add *-*-rtems* to list
diff --git a/gcc/testsuite/g++.dg/warn/pr36921.C b/gcc/testsuite/g++.dg/warn/pr36921.C
new file mode 100644 (file)
index 0000000..7393669
--- /dev/null
@@ -0,0 +1,27 @@
+/* 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(); }
+A operator>(A, A) { return A(); }
+A operator<=(A, A) { return A(); }
+A operator>=(A, A) { return A(); }
+A operator==(A, A) { return A(); }
+A operator!=(A, A) { return A(); }
+
+int main() {
+  A() < A() < A(); // should not emit warning
+  1 < 2 < 3; // { dg-warning "mathematical meaning" "parentheses" }
+  A() > A() > A(); // should not emit warning
+  1 > 2 > 3; // { dg-warning "mathematical meaning" "parentheses" }
+  A() <= A() <= A(); // should not emit warning
+  1 <= 2 <= 3; // { dg-warning "mathematical meaning" "parentheses" }
+  A() >= A() >= A(); // should not emit warning
+  1 >= 2 >= 3; // { dg-warning "mathematical meaning" "parentheses" }
+
+  A() == A() < A (); // { dg-warning "suggest parentheses" "parentheses" }
+  A() < A() != A (); // { dg-warning "suggest parentheses" "parentheses" }
+  return 0;
+}