Skip to content

Map nullptr type to void* instead of the invalid type name null#734

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:fix-nullptr-macro-void-type
Jul 13, 2026
Merged

Map nullptr type to void* instead of the invalid type name null#734
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:fix-nullptr-macro-void-type

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #601.

A macro such as #define VK_NULL_HANDLE nullptr was resolving its CXType_NullPtr type to the literal string null, so --generate-macro-bindings emitted uncompilable code:

[NativeTypeName("#define VK_NULL_HANDLE nullptr")]
public static readonly null VK_NULL_HANDLE = null;

null is not a valid type name. This maps CXType_NullPtr to void* instead, which is exactly how an equivalent #define X ((void*)0) macro is already handled -- it also correctly triggers the unsafe modifier on the containing class via the existing IsUnsafe check:

public static unsafe partial class Methods
{
    [NativeTypeName("#define VK_NULL_HANDLE nullptr")]
    public static readonly void* VK_NULL_HANDLE = null;
}

Added NullPtrMacroBindingTest covering the macro-binding case. Full generator suite is green (3719 passed, 0 failed) with zero golden churn.

Note

This PR was authored with the assistance of Copilot.

tannergooding and others added 2 commits July 12, 2026 23:15
A macro such as `#define VK_NULL_HANDLE nullptr` resolved its
`CXType_NullPtr` type to the literal string `null`, emitting the
uncompilable `public static readonly null VK_NULL_HANDLE = null;`.
Map it to `void*` instead, matching how a `(void*)0` macro is
already handled (including triggering the `unsafe` modifier on the
containing class).

Fixes dotnet#601

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit af4dd33 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the fix-nullptr-macro-void-type branch July 13, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClangSharpPInvokeGenerator does not correctly generate VK_NULL_HANDLE

1 participant