From 55365c7d3082d6af980f741bf8439a23eb3451be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Matos?= Date: Sun, 26 Apr 2020 19:12:03 +0100 Subject: [PATCH] Ignore implicitly deleted copy constructor methods. --- src/Generator/Passes/CheckIgnoredDecls.cs | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index 44e516ca..9d9dee18 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -232,9 +232,48 @@ namespace CppSharp.Passes return true; } + if (method.IsCopyConstructor) + { + if (!CheckNonDeletedCopyConstructor(method)) + return false; + } + return base.VisitMethodDecl(method); } + private static bool CheckNonDeletedCopyConstructor(Method method) + { + if (method.IsDeleted) + { + method.ExplicitlyIgnore(); + + Diagnostics.Debug( + "Copy constructor '{0}' was ignored due to being deleted", + method.QualifiedOriginalName); + + return false; + } + + //Check if base class has an implicitly deleted copy constructor + var baseClass = (method.Namespace as Class).Bases.FirstOrDefault()?.Class; + if (baseClass != null) + { + var baseCopyCtor = baseClass.Methods.Find(m => m.IsCopyConstructor); + if (baseCopyCtor == null || baseCopyCtor.IsDeleted) + { + method.ExplicitlyIgnore(); + + Diagnostics.Debug( + "Copy constructor '{0}' was ignored due to implicitly deleted base copy constructor '{1}'", + method.QualifiedOriginalName, baseClass.Name); + + return false; + } + } + + return true; + } + bool CheckIgnoredBaseOverridenMethod(Method method) { var @class = method.Namespace as Class;