view gcc/testsuite/g++.dg/warn/pr36921.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* 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;
}