Skip to content

Commit 85b6a92

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

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,21 @@ private void WrapConstructor(Method method, string wrapper, string @params)
153153
Context.ParserOptions.IsItaniumLikeAbi).Select(
154154
p => cppTypePrinter.VisitParameter(p)));
155155

156-
string @namespace = method.Namespace.Visit(cppTypePrinter);
157-
Class @class = (Class) method.Namespace;
158-
bool needSubclass = method.Access == AccessSpecifier.Protected || @class.IsAbstract;
159-
if (needSubclass)
156+
if (method.Access != AccessSpecifier.Protected)
157+
Write("extern \"C\" ");
158+
Write($"{GetExporting()}void {wrapper}({signature}) ");
159+
160+
if (method.Access == AccessSpecifier.Protected ||
161+
((Class) method.Namespace).IsAbstract)
160162
{
161-
Write($"extern \"C\" {GetExporting()}void {wrapper}({signature}) ");
162-
WriteLine($"{{ ::new ({Helpers.InstanceField}) {wrapper}{method.Namespace.Name}({@params}); }}");
163+
Write($@"{{ ::new ({Helpers.InstanceField}) {
164+
wrapper}{method.Namespace.Name}({@params}); }}");
165+
WriteLine(method.Access == AccessSpecifier.Protected ? " };" : string.Empty);
163166
}
164167
else
165168
{
166-
Write("extern \"C\" ");
167-
if (needSubclass)
168-
Write($@"class {wrapper}{method.Namespace.Namespace.Name} : public {
169-
method.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
170-
Write($"{GetExporting()}void {wrapper}({signature}) ");
171-
Write($"{{ ::new ({Helpers.InstanceField}) {@namespace}({@params}); }}");
172-
if (needSubclass)
173-
Write("; }");
174-
NewLine();
169+
string @namespace = method.Namespace.Visit(cppTypePrinter);
170+
WriteLine($"{{ ::new ({Helpers.InstanceField}) {@namespace}({@params}); }}");
175171
}
176172

177173
foreach (var param in method.Parameters.Where(p =>

tests/CSharp/CSharp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,10 +1502,11 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
15021502
bool boolean;
15031503
};
15041504

1505-
class DLL_API ProtectedDestructor
1505+
class DLL_API ProtectedConstructorDestructor
15061506
{
15071507
protected:
1508-
~ProtectedDestructor() {}
1508+
ProtectedConstructorDestructor() {}
1509+
~ProtectedConstructorDestructor() {}
15091510
};
15101511

15111512
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];

0 commit comments

Comments
 (0)