diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 64cb5ff3..1a05e9b3 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -310,6 +310,11 @@ private void VisitEnumConstantDecl(EnumConstantDecl enumConstantDecl) private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) { + if (_config.ExcludeAnonymousFieldHelpers) + { + return; + } + if (IsPrevContextDecl(out var prevContext) && prevContext.IsAnonymousStructOrUnion) { // We shouldn't process indirect fields where the prev context is an anonymous record decl diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index cbf374eb..8b11eae8 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -1635,6 +1635,21 @@ private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrT if (IsPrevContextStmt(out var callExpr)) { var index = callExpr.Args.IndexOf(unaryExprOrTypeTraitExpr); + + // If we didn't find the expression, try and find it under an implicit cast + if (index == -1) + { + for (int i = 0; i < callExpr.Args.Count; i++) + { + var arg = callExpr.Args[i]; + if (arg is ImplicitCastExpr implicitCastExpr && implicitCastExpr.SubExprAsWritten == unaryExprOrTypeTraitExpr) + { + index = i; + break; + } + } + } + var calleeDecl = callExpr.CalleeDecl; if (calleeDecl is FunctionDecl functionDecl)