summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/pr36921.C
blob: 7393669101fd9042065ce8f83087663f3d80d60b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}