We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref T
T
unmanaged
Tested with a daily SDK build (7.0.100-preview.7.22358.13):
unsafe { var byref = default(ByReference<int>); var byptr = &byref; // does not error } readonly ref struct ByReference<T> { public readonly ref T Value; }
Expected Behavior: error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('ByReference<int>')
error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('ByReference<int>')
Actual Behavior: The code compiles successfully.
The text was updated successfully, but these errors were encountered:
Worth noting: assuming this is unintended behaviour, it is currently being relied upon by the reflection stack.
Sorry, something went wrong.
It feels like it would be reasonable to make people use https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.aspointer?view=net-6.0 if they want to keep doing this.
Note, for that they'd currently be forced to use a function pointer jump, which adds an extra indirection. As in:
unsafe { var byref = default(ByReference<int>); var f1 = (delegate*<ref byte, ref byte>)&Unsafe.As<byte, byte>; var f2 = (delegate*<ref ByReference<int>, ref byte>)f1; void* byptr = Unsafe.AsPointer(ref f2(ref byref)); }
That said, it would work around the issue until ref struct-s in generics are allowed 😄
ref struct
@jaredpar Did #63209 fix this too?
Thanks for reporting this issue. It has been fixed in #64064.
The compiler now reports:
warning CS8500: This takes the address of, gets the size of, or declares a pointer to a managed type ('ByReference<int>')
cc @jcouv
cston
No branches or pull requests
Tested with a daily SDK build (7.0.100-preview.7.22358.13):
Expected Behavior:
error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('ByReference<int>')
Actual Behavior:
The code compiles successfully.
The text was updated successfully, but these errors were encountered: