• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -std=c++2a -verify %s
2 
3 struct A1 {
4   int x;
5   int &y; // expected-note 9{{because class 'A1' has a reference member}}
6 
7   bool operator==(const A1&) const = default; // expected-warning {{implicitly deleted}} expected-note 2{{deleted here}}
8   bool operator<=>(const A1&) const = default; // expected-warning {{implicitly deleted}} expected-note 5{{deleted here}}
9 };
10 struct A2 {
11   int x;
12   int &y;
13 
14   bool operator==(const A2&) const;
15   bool operator!=(const A2&) const = default;
16 
17   int operator<=>(const A2&) const;
18   bool operator<(const A2&) const = default;
19   bool operator<=(const A2&) const = default;
20   bool operator>(const A2&) const = default;
21   bool operator>=(const A2&) const = default;
22 };
f(A1 a)23 void f(A1 a) {
24   void(a == a); // expected-error {{deleted}}
25   void(a != a); // expected-error {{deleted}}
26   void(a <=> a); // expected-error {{deleted}}
27   void(a < a); // expected-error {{deleted}}
28   void(a <= a); // expected-error {{deleted}}
29   void(a > a); // expected-error {{deleted}}
30   void(a >= a); // expected-error {{deleted}}
31 }
f(A2 a)32 void f(A2 a) {
33   void(a == a);
34   void(a != a);
35   void(a <=> a);
36   void(a < a);
37   void(a <= a);
38   void(a > a);
39   void(a >= a);
40 }
41 
42 struct B1 {
43   struct {
44     int x;
45     int &y; // expected-note 2{{because class 'B1' has a reference member}}
46   };
47 
48   bool operator==(const B1&) const = default; // expected-warning {{implicitly deleted}}
49   bool operator<=>(const B1&) const = default; // expected-warning {{implicitly deleted}}
50 };
51 
52 struct B2 {
53   struct {
54     int x;
55     int &y;
56   };
57 
58   bool operator==(const B2&) const;
59   bool operator!=(const B2&) const = default;
60 
61   bool operator<=>(const B2&) const;
62   bool operator<(const B2&) const = default;
63   bool operator<=(const B2&) const = default;
64   bool operator>(const B2&) const = default;
65   bool operator>=(const B2&) const = default;
66 };
67 
68 union C1 {
69   int a;
70 
71   bool operator==(const C1&) const = default; // expected-warning {{implicitly deleted}} expected-note {{because 'C1' is a union }}
72   bool operator<=>(const C1&) const = default; // expected-warning {{implicitly deleted}} expected-note {{because 'C1' is a union }}
73 };
74 
75 union C2 {
76   int a;
77 
78   bool operator==(const C2&) const;
79   bool operator!=(const C2&) const = default;
80 
81   bool operator<=>(const C2&) const;
82   bool operator<(const C2&) const = default;
83   bool operator<=(const C2&) const = default;
84   bool operator>(const C2&) const = default;
85   bool operator>=(const C2&) const = default;
86 };
87 
88 struct D1 {
89   union {
90     int a;
91   };
92 
93   bool operator==(const D1&) const = default; // expected-warning {{implicitly deleted}} expected-note {{because 'D1' is a union-like class}}
94   bool operator<=>(const D1&) const = default; // expected-warning {{implicitly deleted}} expected-note {{because 'D1' is a union-like class}}
95 };
96 struct D2 {
97   union {
98     int a;
99   };
100 
101   bool operator==(const D2&) const;
102   bool operator!=(const D2&) const = default;
103 
104   bool operator<=>(const D2&) const;
105   bool operator<(const D2&) const = default;
106   bool operator<=(const D2&) const = default;
107   bool operator>(const D2&) const = default;
108   bool operator>=(const D2&) const = default;
109 };
110 
111 union E1 {
112   bool operator==(const E1&) const = default;
113   bool operator!=(const E1&) const = default;
114 
115   bool operator<=>(const E1&) const = default;
116   bool operator<(const E1&) const = default;
117   bool operator<=(const E1&) const = default;
118   bool operator>(const E1&) const = default;
119   bool operator>=(const E1&) const = default;
120 };
121 union E2 {
122   bool operator==(const E2&) const = default;
123   bool operator!=(const E2&) const = default;
124 
125   bool operator<=>(const E2&) const = default;
126   bool operator<(const E2&) const = default;
127   bool operator<=(const E2&) const = default;
128   bool operator>(const E2&) const = default;
129   bool operator>=(const E2&) const = default;
130 };
131 
132 struct F;
133 bool operator==(const F&, const F&);
134 bool operator!=(const F&, const F&);
135 bool operator<=>(const F&, const F&);
136 bool operator<(const F&, const F&);
137 struct F {
138   union { int a; };
139   friend bool operator==(const F&, const F&) = default; // expected-error {{defaulting this equality comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
140   friend bool operator!=(const F&, const F&) = default;
141   friend bool operator<=>(const F&, const F&) = default; // expected-error {{defaulting this three-way comparison operator would delete it after its first declaration}} expected-note {{implicitly deleted because 'F' is a union-like class}}
142   friend bool operator<(const F&, const F&) = default;
143 };
144