Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ private string GetRemappedCursorName(NamedDecl namedDecl)
return remappedName;
}

if ((namedDecl is FieldDecl fieldDecl) && name.StartsWith("__AnonymousField_"))
if ((namedDecl is FieldDecl fieldDecl) && name.StartsWith("__AnonymousFieldDecl_"))
{
remappedName = "Anonymous";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,61 @@ public static int MyFunction()
await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents);
}

[Fact]
public async Task AccessUnionMemberTest()
{
var inputContents = @"union MyUnion
{
struct { int a; };
};

void MyFunction()
{
MyUnion myUnion;
myUnion.a = 10;
}
";

var expectedOutputContents = @"using System.Runtime.InteropServices;

namespace ClangSharp.Test
{
[StructLayout(LayoutKind.Explicit)]
public partial struct MyUnion
{
[FieldOffset(0)]
[NativeTypeName(""MyUnion::(anonymous struct at ClangUnsavedFile.h:3:5)"")]
public _Anonymous_e__Struct Anonymous;

public ref int a
{
get
{
return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1));
}
}

public partial struct _Anonymous_e__Struct
{
public int a;
}
}

public static partial class Methods
{
public static void MyFunction()
{
MyUnion myUnion = new MyUnion();

myUnion.Anonymous.a = 10;
}
}
}
";

await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents);
}

[Fact]
public async Task ReturnStructTest()
{
Expand Down