1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a
2 
3 int foo(int x) {
4   return x == x; // expected-warning {{self-comparison always evaluates to true}}
5 }
6 
7 struct X {
8   bool operator==(const X &x);
9 };
10 
11 struct A {
12   int x;
13   X x2;
14   int a[3];
15   int b[3];
16   bool f() { return x == x; } // expected-warning {{self-comparison always evaluates to true}}
17   bool g() { return x2 == x2; } // no-warning
18   bool h() { return a == b; } // expected-warning {{array comparison always evaluates to false}}
19   bool i() {
20     int c[3];
21     return a == c; // expected-warning {{array comparison always evaluates to false}}
22   }
23 };
24 
25 namespace NA { extern "C" int x[3]; }
26 namespace NB { extern "C" int x[3]; }
27 bool k = NA::x == NB::x; // expected-warning {{self-comparison always evaluates to true}}
28 
29 template<typename T> struct Y { static inline int n; };
30 bool f() {
31   return
32     Y<int>::n == Y<int>::n || // expected-warning {{self-comparison always evaluates to true}}
33     Y<void>::n == Y<int>::n;
34 }
35 template<typename T, typename U>
36 bool g() {
37   // FIXME: Ideally we'd produce a self-comparison warning on the first of these.
38   return
39     Y<T>::n == Y<T>::n ||
40     Y<T>::n == Y<U>::n;
41 }
42 template bool g<int, int>(); // should not produce any warnings
43