1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a
4 return x
== x
; // expected-warning {{self-comparison always evaluates to true}}
8 bool operator==(const X
&x
) const;
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}} expected-warning {{deprecated}}
21 return a
== c
; // expected-warning {{array comparison always evaluates to false}} expected-warning {{deprecated}}
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}} expected-warning {{deprecated}}
29 template<typename T
> struct Y
{ static inline int n
; };
32 Y
<int>::n
== Y
<int>::n
|| // expected-warning {{self-comparison always evaluates to true}}
33 Y
<void>::n
== Y
<int>::n
;
35 template<typename T
, typename U
>
37 // FIXME: Ideally we'd produce a self-comparison warning on the first of these.
42 template bool g
<int, int>(); // should not produce any warnings
44 namespace member_tests
{
47 static int static_field
;
49 return field
== field
; // expected-warning {{self-comparison always evaluates to true}}
50 return static_field
== static_field
; // expected-warning {{self-comparison always evaluates to true}}
51 return static_field
== b
.static_field
; // expected-warning {{self-comparison always evaluates to true}}
52 return B::static_field
== this->static_field
; // expected-warning {{self-comparison always evaluates to true}}
53 return this == this; // expected-warning {{self-comparison always evaluates to true}}
55 return field
== b
.field
;
56 return this->field
== b
.field
;
68 static int static_field
;
74 static int static_field
;
79 int struct_test(S s1
, S s2
, S
*s3
, T t
) {
80 return s1
.field
== s1
.field
; // expected-warning {{self-comparison always evaluates to true}}
81 return s2
.field
== s2
.field
; // expected-warning {{self-comparison always evaluates to true}}
82 return s1
.static_field
== s2
.static_field
; // expected-warning {{self-comparison always evaluates to true}}
83 return S::static_field
== s1
.static_field
; // expected-warning {{self-comparison always evaluates to true}}
84 return s1
.array
== s1
.array
; // expected-warning {{self-comparison always evaluates to true}} expected-warning {{deprecated}}
85 return t
.s
.static_field
== S::static_field
; // expected-warning {{self-comparison always evaluates to true}}
86 return s3
->field
== s3
->field
; // expected-warning {{self-comparison always evaluates to true}}
87 return s3
->static_field
== S::static_field
; // expected-warning {{self-comparison always evaluates to true}}
88 return s1
.array
[0] == s1
.array
[0]; // expected-warning {{self-comparison always evaluates to true}}
89 return s1
.array
[0] == s1
.array
[0ull]; // expected-warning {{self-comparison always evaluates to true}}
90 return s1
.array
[I1
] == s1
.array
[I1
]; // expected-warning {{self-comparison always evaluates to true}}
91 return s1
.array
[s2
.array
[0]] == s1
.array
[s2
.array
[0]]; // expected-warning {{self-comparison always evaluates to true}}
92 return s3
->array
[t
.field
] == s3
->array
[t
.field
]; // expected-warning {{self-comparison always evaluates to true}}
95 return t
.field
== t
.field
; // expected-warning {{self-comparison always evaluates to true}}
96 return t
.field
<= t
.field
; // expected-warning {{self-comparison always evaluates to true}}
97 return t
.field
>= t
.field
; // expected-warning {{self-comparison always evaluates to true}}
99 return t
.field
!= t
.field
; // expected-warning {{self-comparison always evaluates to false}}
100 return t
.field
< t
.field
; // expected-warning {{self-comparison always evaluates to false}}
101 return t
.field
> t
.field
; // expected-warning {{self-comparison always evaluates to false}}
104 return s1
.field
== s2
.field
;
105 return s2
.array
== s1
.array
; // FIXME: This always evaluates to false. expected-warning {{deprecated}}
106 return s2
.array
[0] == s1
.array
[0];
107 return s1
.array
[I1
] == s1
.array
[I2
];
109 return s1
.static_field
== t
.static_field
;
113 bool operator!=(const U
&);
116 bool operator==(const U
&, const U
&);
118 // May want to warn on this in the future.
119 int user_defined(U u
) {
124 } // namespace member_tests