Skip to content

fix InvalidCastException when inheriting c++ struct constructors #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ private void VisitEnumDecl(EnumDecl enumDecl)
{
var typeName = GetRemappedTypeName(enumDecl, context: null, enumDecl.IntegerType, out var nativeTypeName);

desc = new EnumDesc()
{
desc = new EnumDesc() {
AccessSpecifier = accessSpecifier,
TypeName = typeName,
EscapedName = escapedName,
Expand Down Expand Up @@ -662,8 +661,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
if (needsReturnFixup)
{
_outputBuilder.WriteParameterSeparator();
parameterDesc = new()
{
parameterDesc = new() {
Name = "_result",
Type = $"{returnTypeName}*"
};
Expand All @@ -685,8 +683,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
{
_outputBuilder.WriteParameterSeparator();
}
var parameterDesc = new ParameterDesc
{
var parameterDesc = new ParameterDesc {
Name = "",
Type = "__arglist"
};
Expand Down Expand Up @@ -815,9 +812,11 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI
{
continue;
}

var memberRef = (Ref)cxxConstructorDecl.CursorChildren[i];
var memberInit = (Stmt)cxxConstructorDecl.CursorChildren[++i];
if (cxxConstructorDecl.CursorChildren[i] is not Ref memberRef
|| cxxConstructorDecl.CursorChildren[++i] is not Stmt memberInit)
{
continue;
}

if (memberInit is ImplicitValueInitExpr)
{
Expand All @@ -827,7 +826,7 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI
var memberRefName = GetRemappedCursorName(memberRef.Referenced);
var memberInitName = memberInit.Spelling;

if (memberInit is CastExpr {SubExprAsWritten: DeclRefExpr declRefExpr})
if (memberInit is CastExpr { SubExprAsWritten: DeclRefExpr declRefExpr })
{
memberInitName = GetRemappedCursorName(declRefExpr.Decl);
}
Expand Down Expand Up @@ -859,6 +858,7 @@ void VisitCtorInitializers(CXXConstructorDecl cxxConstructorDecl, int firstCtorI
{
_outputBuilder.EndConstructorInitializer();
}

}
}
}
Expand Down Expand Up @@ -1319,8 +1319,7 @@ void ForTypedefDecl(ParmVarDecl parmVarDecl, TypedefDecl typedefDecl)
escapedName += index;
}

var desc = new ParameterDesc
{
var desc = new ParameterDesc {
Name = escapedName,
Type = typeName,
NativeTypeName = nativeTypeName,
Expand Down Expand Up @@ -2139,8 +2138,7 @@ void OutputVtblEntry(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl)
var remappedName = FixupNameForMultipleHits(cxxMethodDecl);
var escapedName = EscapeAndStripMethodName(remappedName);

var desc = new FieldDesc
{
var desc = new FieldDesc {
AccessSpecifier = AccessSpecifier.Public,
NativeTypeName = nativeTypeName,
EscapedName = escapedName,
Expand Down Expand Up @@ -2954,7 +2952,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co
var arraySize = Math.Max((arrayType as ConstantArrayType)?.Size ?? 0, 1);
var totalSize = arraySize;
var totalSizeString = $"{arraySize}";
var sizePerDimension = new List<(long index, long size)>() {(0, arraySize) };
var sizePerDimension = new List<(long index, long size)>() { (0, arraySize) };

while (IsTypeConstantOrIncompleteArray(recordDecl, elementType, out var subArrayType))
{
Expand Down
Loading