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