From d741ced55aa022ee02ebac01d751ad5d6614b7db Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Thu, 24 Dec 2020 01:43:22 +0200 Subject: [PATCH] Generate valid C++ for protected destructors Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/SymbolsCodeGenerator.cs | 17 ++++++++++------- tests/CSharp/CSharp.h | 6 ++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Generator/Passes/SymbolsCodeGenerator.cs b/src/Generator/Passes/SymbolsCodeGenerator.cs index 9982d7ba..1adfb430 100644 --- a/src/Generator/Passes/SymbolsCodeGenerator.cs +++ b/src/Generator/Passes/SymbolsCodeGenerator.cs @@ -201,21 +201,24 @@ namespace CppSharp.Passes bool needSubclass = method.Access == AccessSpecifier.Protected || ((Class) method.Namespace).IsAbstract; string @namespace = method.Namespace.Visit(cppTypePrinter); - Write("extern \"C\" "); + if (!needSubclass) + Write("extern \"C\" "); Write($"{GetExporting()}void {wrapper}"); if (needSubclass) Write("Protected"); string instance = Helpers.InstanceField; - string @class = needSubclass ? wrapper : @namespace; - Write($"({@class}* {instance}) {{ {instance}->~{method.Namespace.Name}(); }};"); if (needSubclass) { - NewLine(); - Write($@"extern ""C"" {GetExporting()}void {wrapper}({wrapper}* {instance}) {{ { - instance}->{wrapper}Protected({instance}); }}"); + string @class = wrapper + method.Namespace.Name; + WriteLine($"() {{ this->~{@class}(); }} }};"); + Write($@"extern ""C"" {GetExporting()}void {wrapper}({ + @class}* {instance}) {{ {instance}->{wrapper}Protected"); } - NewLine(); + else + Write($@"({$"{@namespace}*{instance}"}) {{ { + instance}->~{method.Namespace.Name}"); + WriteLine("(); }"); } private void TakeFunctionAddress(Function function, string wrapper) diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 628468ad..fb241ba1 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -1502,6 +1502,12 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase bool boolean; }; +class DLL_API ProtectedDestructor +{ +protected: + ~ProtectedDestructor() {} +}; + DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5]; DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2]; DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4];