Skip to content

Commit d741ced

Browse files
committed
Generate valid C++ for protected destructors
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 1020e18 commit d741ced

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,24 @@ private void WrapDestructor(Method method, string wrapper)
201201
bool needSubclass = method.Access == AccessSpecifier.Protected ||
202202
((Class) method.Namespace).IsAbstract;
203203
string @namespace = method.Namespace.Visit(cppTypePrinter);
204-
Write("extern \"C\" ");
204+
if (!needSubclass)
205+
Write("extern \"C\" ");
205206
Write($"{GetExporting()}void {wrapper}");
206207
if (needSubclass)
207208
Write("Protected");
208209

209210
string instance = Helpers.InstanceField;
210-
string @class = needSubclass ? wrapper : @namespace;
211-
Write($"({@class}* {instance}) {{ {instance}->~{method.Namespace.Name}(); }};");
212211
if (needSubclass)
213212
{
214-
NewLine();
215-
Write($@"extern ""C"" {GetExporting()}void {wrapper}({wrapper}* {instance}) {{ {
216-
instance}->{wrapper}Protected({instance}); }}");
213+
string @class = wrapper + method.Namespace.Name;
214+
WriteLine($"() {{ this->~{@class}(); }} }};");
215+
Write($@"extern ""C"" {GetExporting()}void {wrapper}({
216+
@class}* {instance}) {{ {instance}->{wrapper}Protected");
217217
}
218-
NewLine();
218+
else
219+
Write($@"({$"{@namespace}*{instance}"}) {{ {
220+
instance}->~{method.Namespace.Name}");
221+
WriteLine("(); }");
219222
}
220223

221224
private void TakeFunctionAddress(Function function, string wrapper)

tests/CSharp/CSharp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,12 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
15021502
bool boolean;
15031503
};
15041504

1505+
class DLL_API ProtectedDestructor
1506+
{
1507+
protected:
1508+
~ProtectedDestructor() {}
1509+
};
1510+
15051511
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];
15061512
DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2];
15071513
DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4];

0 commit comments

Comments
 (0)