1 // RUN: %check_clang_tidy %s modernize-use-equals-delete %t
2 
3 struct PositivePrivate {
4 private:
5   PositivePrivate();
6   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
7   // CHECK-FIXES: PositivePrivate() = delete;
8   PositivePrivate(const PositivePrivate &);
9   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
10   // CHECK-FIXES: PositivePrivate(const PositivePrivate &) = delete;
11   PositivePrivate &operator=(const PositivePrivate &);
12   // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
13   // CHECK-FIXES: PositivePrivate &operator=(const PositivePrivate &) = delete;
14   PositivePrivate(PositivePrivate &&);
15   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
16   // CHECK-FIXES: PositivePrivate(PositivePrivate &&) = delete;
17   PositivePrivate &operator=(PositivePrivate &&);
18   // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
19   // CHECK-FIXES: PositivePrivate &operator=(PositivePrivate &&) = delete;
20   ~PositivePrivate();
21   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
22   // CHECK-FIXES: ~PositivePrivate() = delete;
23 };
24 
25 template<typename T>
26 struct PositivePrivateTemplate {
27 private:
28   PositivePrivateTemplate();
29   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
30   // CHECK-FIXES: PositivePrivateTemplate() = delete;
31   PositivePrivateTemplate(const PositivePrivateTemplate &);
32   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
33   // CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = delete;
34   PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
35   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
36   // CHECK-FIXES: PositivePrivateTemplate &operator=(const PositivePrivateTemplate &) = delete;
37   PositivePrivateTemplate(PositivePrivateTemplate &&);
38   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
39   // CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
40   PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
41   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
42   // CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate &&) = delete;
43   ~PositivePrivateTemplate();
44   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
45   // CHECK-FIXES: ~PositivePrivateTemplate() = delete;
46 };
47 
48 template struct PositivePrivateTemplate<int>;
49 template struct PositivePrivateTemplate<char>;
50 
51 struct NegativePublic {
52   NegativePublic(const NegativePublic &);
53 };
54 
55 struct NegativeProtected {
56 protected:
57   NegativeProtected(const NegativeProtected &);
58 };
59 
60 struct PositiveInlineMember {
fooPositiveInlineMember61   int foo() { return 0; }
62 
63 private:
64   PositiveInlineMember(const PositiveInlineMember &);
65   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
66   // CHECK-FIXES: PositiveInlineMember(const PositiveInlineMember &) = delete;
67 };
68 
69 struct PositiveOutOfLineMember {
70   int foo();
71 
72 private:
73   PositiveOutOfLineMember(const PositiveOutOfLineMember &);
74   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
75   // CHECK-FIXES: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete;
76 };
77 
foo()78 int PositiveOutOfLineMember::foo() { return 0; }
79 
80 struct PositiveAbstractMember {
81   virtual int foo() = 0;
82 
83 private:
84   PositiveAbstractMember(const PositiveAbstractMember &);
85   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
86   // CHECK-FIXES: PositiveAbstractMember(const PositiveAbstractMember &) = delete;
87 };
88 
89 struct NegativeMemberNotImpl {
90   int foo();
91 
92 private:
93   NegativeMemberNotImpl(const NegativeMemberNotImpl &);
94 };
95 
96 struct NegativeStaticMemberNotImpl {
97   static int foo();
98 
99 private:
100   NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
101 };
102 
103 struct NegativeInline {
104 private:
NegativeInlineNegativeInline105   NegativeInline(const NegativeInline &) {}
106 };
107 
108 struct NegativeOutOfLine {
109 private:
110   NegativeOutOfLine(const NegativeOutOfLine &);
111 };
112 
NegativeOutOfLine(const NegativeOutOfLine &)113 NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
114 
115 struct NegativeConstructNotImpl {
116   NegativeConstructNotImpl();
117 
118 private:
119   NegativeConstructNotImpl(const NegativeConstructNotImpl &);
120 };
121 
122 struct PositiveDefaultedConstruct {
123   PositiveDefaultedConstruct() = default;
124 
125 private:
126   PositiveDefaultedConstruct(const PositiveDefaultedConstruct &);
127   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
128   // CHECK-FIXES: PositiveDefaultedConstruct(const PositiveDefaultedConstruct &) = delete;
129 };
130 
131 struct PositiveDeletedConstruct {
132   PositiveDeletedConstruct() = delete;
133 
134 private:
135   PositiveDeletedConstruct(const PositiveDeletedConstruct &);
136   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
137   // CHECK-FIXES: PositiveDeletedConstruct(const PositiveDeletedConstruct &) = delete;
138 };
139 
140 struct NegativeDefaulted {
141 private:
142   NegativeDefaulted(const NegativeDefaulted &) = default;
143 };
144 
145 struct PrivateDeleted {
146 private:
147   PrivateDeleted(const PrivateDeleted &) = delete;
148   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
149 };
150 
151 struct ProtectedDeleted {
152 protected:
153   ProtectedDeleted(const ProtectedDeleted &) = delete;
154   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
155 };
156 
157 struct PublicDeleted {
158 public:
159   PublicDeleted(const PublicDeleted &) = delete;
160 };
161 
162 #define M1                                                         \
163   struct PrivateDeletedMacro {                                     \
164   private:                                                         \
165     PrivateDeletedMacro(const PrivateDeletedMacro &) = delete;     \
166   };                                                               \
167   struct ProtectedDeletedMacro {                                   \
168   protected:                                                       \
169     ProtectedDeletedMacro(const ProtectedDeletedMacro &) = delete; \
170   }
171 
172 M1;
173 
174 #define DISALLOW_COPY_AND_ASSIGN(name) \
175   name(const name &) = delete;         \
176   void operator=(const name &) = delete
177 
178 struct PrivateDeletedMacro2 {
179 private:
180   DISALLOW_COPY_AND_ASSIGN(PrivateDeletedMacro2);
181 };
182 
183 struct ProtectedDeletedMacro2 {
184 protected:
185   DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
186 };
187 
188 // This resulted in a warning by default.
189 #define MACRO(type) void operator=(type const &)
190 class C {
191 private:
192   MACRO(C);
193 };
194