* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@142849
138bc75d-0d04-0410-961f-
82ee72b054a4
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)
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;
+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
+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
--- /dev/null
+/* 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;
+}