Degrade gracefully on C++ pointer-to-member types#771
Merged
tannergooding merged 1 commit intoJul 14, 2026
Merged
Conversation
Emit an opaque 'void*' with the original spelling preserved via NativeTypeName and a warning, instead of hard-erroring the whole run when a field has a member-pointer type. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
C++ pointer-to-member types (
int MyClass::*,void (MyClass::*)()) were unsupported: the type-class switch never mappedCX_TypeClass_MemberPointer, soGetTypeNamefell through to the raw Clang spelling (int MyClass::*, which isn't valid C#) andGetTypeSizehard-errored withUnsupported type: 'CX_TypeClass_MemberPointer'. The containing struct then couldn't be laid out.These have no direct C# equivalent, so this degrades gracefully rather than erroring:
GetTypeNameemits an opaquevoid*and preserves the original spelling via[NativeTypeName(...)]plus a single warning, andGetTypeSizetreats member pointers as pointer-sized (added to the existingFunctionType or PointerType or ReferenceTypebranch).Caveat, called out in the warning: a member-function pointer can be wider than a data pointer under both the Itanium and MSVC ABIs, so
void*may under-size those. Getting the exact width right is ABI-specific and left as a separate follow-up; this change is about not hard-erroring and keeping the struct usable.Adds a golden regression test (
MemberPointerDeclarationTest) covering data- and function-member pointers, with per-OS expected diagnostics (MSVC additionally emits anMSInheritanceattribute warning; Itanium does not).Fixes #511