Skip to content

Missing type cast for sizeof macro #836

Description

@Exanite

The following test case, when ran on Windows, results in the following code.
The output does not compile since it is missing an explicit cast from int to ulong.

Notably, the void* field is important for this edge case. Without it, the generator simply outputs 0.

[Test]
public Task RuntimeSizeofMacroTest()
{
    var inputContents = """
        typedef struct XrEventDataBuffer {
            const void* next;
        } XrEventDataBuffer;

        #define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)
        """;

    return ValidateGeneratedCSharpLatestWindowsBaselineAsync(inputContents, PInvokeGeneratorConfigurationOptions.GenerateUnmanagedConstants);
}
namespace ClangSharp.Test
{
    public unsafe partial struct XrEventDataBuffer
    {
        [NativeTypeName("const void *")]
        public void* next;
    }

    public static unsafe partial class Methods
    {
        [NativeTypeName("#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)")]
        public static ulong XR_MAX_EVENT_DATA_SIZE => sizeof(XrEventDataBuffer);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions