modernize-use-equals-delete.cpp
7.4 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// RUN: %check_clang_tidy %s modernize-use-equals-delete %t
struct PositivePrivate {
private:
PositivePrivate();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivate() = delete;
PositivePrivate(const PositivePrivate &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivate(const PositivePrivate &) = delete;
PositivePrivate &operator=(const PositivePrivate &);
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivate &operator=(const PositivePrivate &) = delete;
PositivePrivate(PositivePrivate &&);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivate(PositivePrivate &&) = delete;
PositivePrivate &operator=(PositivePrivate &&);
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivate &operator=(PositivePrivate &&) = delete;
~PositivePrivate();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: ~PositivePrivate() = delete;
};
template<typename T>
struct PositivePrivateTemplate {
private:
PositivePrivateTemplate();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivateTemplate() = delete;
PositivePrivateTemplate(const PositivePrivateTemplate &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = delete;
PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivateTemplate &operator=(const PositivePrivateTemplate &) = delete;
PositivePrivateTemplate(PositivePrivateTemplate &&);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate &&) = delete;
~PositivePrivateTemplate();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: ~PositivePrivateTemplate() = delete;
};
template struct PositivePrivateTemplate<int>;
template struct PositivePrivateTemplate<char>;
struct NegativePublic {
NegativePublic(const NegativePublic &);
};
struct NegativeProtected {
protected:
NegativeProtected(const NegativeProtected &);
};
struct PositiveInlineMember {
int foo() { return 0; }
private:
PositiveInlineMember(const PositiveInlineMember &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositiveInlineMember(const PositiveInlineMember &) = delete;
};
struct PositiveOutOfLineMember {
int foo();
private:
PositiveOutOfLineMember(const PositiveOutOfLineMember &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete;
};
int PositiveOutOfLineMember::foo() { return 0; }
struct PositiveAbstractMember {
virtual int foo() = 0;
private:
PositiveAbstractMember(const PositiveAbstractMember &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositiveAbstractMember(const PositiveAbstractMember &) = delete;
};
struct NegativeMemberNotImpl {
int foo();
private:
NegativeMemberNotImpl(const NegativeMemberNotImpl &);
};
struct NegativeStaticMemberNotImpl {
static int foo();
private:
NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
};
struct NegativeInline {
private:
NegativeInline(const NegativeInline &) {}
};
struct NegativeOutOfLine {
private:
NegativeOutOfLine(const NegativeOutOfLine &);
};
NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
struct NegativeConstructNotImpl {
NegativeConstructNotImpl();
private:
NegativeConstructNotImpl(const NegativeConstructNotImpl &);
};
struct PositiveDefaultedConstruct {
PositiveDefaultedConstruct() = default;
private:
PositiveDefaultedConstruct(const PositiveDefaultedConstruct &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositiveDefaultedConstruct(const PositiveDefaultedConstruct &) = delete;
};
struct PositiveDeletedConstruct {
PositiveDeletedConstruct() = delete;
private:
PositiveDeletedConstruct(const PositiveDeletedConstruct &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
// CHECK-FIXES: PositiveDeletedConstruct(const PositiveDeletedConstruct &) = delete;
};
struct NegativeDefaulted {
private:
NegativeDefaulted(const NegativeDefaulted &) = default;
};
struct PrivateDeleted {
private:
PrivateDeleted(const PrivateDeleted &) = delete;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
};
struct ProtectedDeleted {
protected:
ProtectedDeleted(const ProtectedDeleted &) = delete;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
};
struct PublicDeleted {
public:
PublicDeleted(const PublicDeleted &) = delete;
};
#define M1 \
struct PrivateDeletedMacro { \
private: \
PrivateDeletedMacro(const PrivateDeletedMacro &) = delete; \
}; \
struct ProtectedDeletedMacro { \
protected: \
ProtectedDeletedMacro(const ProtectedDeletedMacro &) = delete; \
}
M1;
#define DISALLOW_COPY_AND_ASSIGN(name) \
name(const name &) = delete; \
void operator=(const name &) = delete
struct PrivateDeletedMacro2 {
private:
DISALLOW_COPY_AND_ASSIGN(PrivateDeletedMacro2);
};
struct ProtectedDeletedMacro2 {
protected:
DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
};
// This resulted in a warning by default.
#define MACRO(type) void operator=(type const &)
class C {
private:
MACRO(C);
};