Skip to content

Commit 988a319

Browse files
committed
Add a diagnostic when offsetof is used with DisableRuntimeMarshalling
1 parent 82ba1e3 commit 988a319

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ private void VisitRecordDecl(RecordDecl recordDecl)
16741674
}
16751675
}
16761676

1677-
if ((_testOutputBuilder is not null) && generateTestsClass)
1677+
if ((_testOutputBuilder is not null) && generateTestsClass && !_config.GenerateDisableRuntimeMarshalling)
16781678
{
16791679
_testOutputBuilder.WriteIndented("/// <summary>Validates that the <see cref=\"");
16801680
_testOutputBuilder.Write(escapedName);

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,11 @@ private void VisitUnaryOperator(UnaryOperator unaryOperator)
28412841

28422842
private void VisitOffsetOfExpr(OffsetOfExpr offsetOfExpr)
28432843
{
2844+
if (_config.GenerateDisableRuntimeMarshalling)
2845+
{
2846+
AddDiagnostic(DiagnosticLevel.Warning, $"OffsetOf is unsupported when DisableRuntimeMarshalling is enabled. Generated bindings may be incomplete.", offsetOfExpr);
2847+
}
2848+
28442849
var outputBuilder = StartCSharpCode();
28452850

28462851
outputBuilder.AddUsingDirective("System.Runtime.InteropServices");

0 commit comments

Comments
 (0)