Skip to content

Commit 55365c7

Browse files
committed
Ignore implicitly deleted copy constructor methods.
1 parent 29adf57 commit 55365c7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Generator/Passes/CheckIgnoredDecls.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,48 @@ public override bool VisitMethodDecl(Method method)
232232
return true;
233233
}
234234

235+
if (method.IsCopyConstructor)
236+
{
237+
if (!CheckNonDeletedCopyConstructor(method))
238+
return false;
239+
}
240+
235241
return base.VisitMethodDecl(method);
236242
}
237243

244+
private static bool CheckNonDeletedCopyConstructor(Method method)
245+
{
246+
if (method.IsDeleted)
247+
{
248+
method.ExplicitlyIgnore();
249+
250+
Diagnostics.Debug(
251+
"Copy constructor '{0}' was ignored due to being deleted",
252+
method.QualifiedOriginalName);
253+
254+
return false;
255+
}
256+
257+
//Check if base class has an implicitly deleted copy constructor
258+
var baseClass = (method.Namespace as Class).Bases.FirstOrDefault()?.Class;
259+
if (baseClass != null)
260+
{
261+
var baseCopyCtor = baseClass.Methods.Find(m => m.IsCopyConstructor);
262+
if (baseCopyCtor == null || baseCopyCtor.IsDeleted)
263+
{
264+
method.ExplicitlyIgnore();
265+
266+
Diagnostics.Debug(
267+
"Copy constructor '{0}' was ignored due to implicitly deleted base copy constructor '{1}'",
268+
method.QualifiedOriginalName, baseClass.Name);
269+
270+
return false;
271+
}
272+
}
273+
274+
return true;
275+
}
276+
238277
bool CheckIgnoredBaseOverridenMethod(Method method)
239278
{
240279
var @class = method.Namespace as Class;

0 commit comments

Comments
 (0)