1 // RUN: %clang_cc1 -std=c++2a -verify %s
2 
3 struct A {};
4 struct B { bool operator==(B) const; };
5 struct C { int operator==(C) const; };
6 struct D {
7   // expected-note@+2 {{candidate function not viable: 'this' argument has type 'const}}
8   // expected-note@+1 {{candidate function (with reversed parameter order) not viable: 1st argument ('const}}
9   bool operator==(D);
10 };
11 struct E {
12   E(const E &) = delete; // expected-note {{deleted}}
13   int operator==(E) const; // expected-note {{passing}}
14 };
15 struct F { void operator==(F) const; };
16 struct G { bool operator==(G) const = delete; }; // expected-note {{deleted here}}
17 
18 template<typename T> struct X {
19   X();
20   bool operator==(const X&) const = default; // #x expected-note 4{{deleted here}}
21   T t; // expected-note 3{{because there is no viable comparison function for member 't'}}
22        // expected-note@-1 {{because it would invoke a deleted comparison function for member 't'}}
23 };
24 
25 struct Mutable {
26   bool operator==(const Mutable&) const = default;
27   mutable D d;
28 };
29 
30 void test() {
31   void(X<A>() == X<A>()); // expected-error {{cannot be compared because its 'operator==' is implicitly deleted}}
32   void(X<B>() == X<B>());
33   void(X<C>() == X<C>());
34   void(X<D>() == X<D>()); // expected-error {{cannot be compared because its 'operator==' is implicitly deleted}}
35   void(Mutable() == Mutable());
36 
37   // FIXME: We would benefit from a note identifying the member of 'X' we were comparing here and below.
38   // expected-error@#x {{call to deleted constructor of 'E'}}
39   void(X<E>() == X<E>()); // expected-note {{in defaulted equality comparison operator for 'X<E>' first required here}}
40 
41   // FIXME: We would benefit from a note pointing at the selected 'operator==' here.
42   // expected-error@#x {{value of type 'void' is not contextually convertible to 'bool'}}
43   void(X<F>() == X<F>()); // expected-note {{in defaulted equality comparison operator for 'X<F>' first required here}}
44 
45   void(X<G>() == X<G>()); // expected-error {{cannot be compared because its 'operator==' is implicitly deleted}}
46 
47   void(X<A[3]>() == X<A[3]>()); // expected-error {{cannot be compared because its 'operator==' is implicitly deleted}}
48   void(X<B[3]>() == X<B[3]>());
49 }
50