-
Notifications
You must be signed in to change notification settings - Fork 89
Add the rules for relaxing ref safety restrictions in an unsafe
context.
#941
New issue
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
Conversation
Add the rules for relaxing ref safety restrictions in an `unsafe` context. I read through the grammar, and I don't believe any changes are necessary to allow pointer variables with the `ref`, `in`, or `out` modifiers. However, text regarding `out` and `ref` parameters has been modified to include `in` parameters. Text regarding returning pointer types now includes returning pointer types by `ref` or `readonly ref`. Fixes dotnet#886
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS this does not fix the grammar problems for which #886 was originally opened.
Other than establishing an unsafe context, thus permitting the use of pointer types, the `unsafe` modifier has no effect on a type or a member. | ||
The `unsafe` modifier establishes an unsafe context, thus permitting the use of pointer types. In addition, the following compile-time restrictions are modified in an unsafe context: | ||
|
||
- All safe-context restrictions (§16.4.12.1) are reported as compile-time warnings instead of errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this belong in C# 7.x? I thought it was a later change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal dotnet/csharplang#6476
Meeting notes https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-21.md#unsafer-unsafeness "Approved for C# 11."
According to #841 (comment) it does not affect C# 7.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. I got caught by the "Setting LangVersion is almost the same as using the older compiler" concern.
Thanks for spotting this.
Opened #943 for the grammar updates.
Retarget to C# 11, file a new issue for the feature, and leave #886 for the grammar. |
`unsafe` and ref returns are allowed for delegates, local functions, and methods. Update the grammar for that part. Fixes dotnet#886 See dotnet#941 (review)
This change from dotnet#941 should be made in 7.3
Closing for now - it's so far in the future that this PR won't be useful. But @BillWagner will add an issue to remind us. |
`unsafe` and ref returns are allowed for delegates, local functions, and methods. Update the grammar for that part. Fixes #886 See #941 (review)
This change from #941 should be made in 7.3
I read through the grammar, and I don't believe any changes are necessary to allow pointer variables with the
ref
,in
, orout
modifiers. However, text regardingout
andref
parameters has been modified to includein
parameters. Text regarding returning pointer types now includes returning pointer types byref
orreadonly ref
.Fixes #886