Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

BillWagner
Copy link
Member

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 #886

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
Copy link
Contributor

@KalleOlaviNiemitalo KalleOlaviNiemitalo left a 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.
Copy link
Contributor

@KalleOlaviNiemitalo KalleOlaviNiemitalo Sep 19, 2023

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@BillWagner BillWagner Sep 20, 2023

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.

@KalleOlaviNiemitalo
Copy link
Contributor

Retarget to C# 11, file a new issue for the feature, and leave #886 for the grammar.

BillWagner added a commit to BillWagner/csharpstandard that referenced this pull request Sep 20, 2023
`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)
BillWagner added a commit to BillWagner/csharpstandard that referenced this pull request Sep 20, 2023
This change from dotnet#941 should be made in 7.3
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Sep 20, 2023
@jskeet jskeet modified the milestone: C# 7.x Sep 20, 2023
@jskeet
Copy link
Contributor

jskeet commented Sep 20, 2023

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.

@jskeet jskeet closed this Sep 20, 2023
jskeet pushed a commit that referenced this pull request Sep 20, 2023
`unsafe` and ref returns are allowed for delegates, local functions, and methods. Update the grammar for that part.

Fixes #886

See #941 (review)
jskeet pushed a commit that referenced this pull request Sep 20, 2023
This change from #941 should be made in 7.3
@BillWagner BillWagner deleted the ref-and-unsafe branch September 20, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate combinations of unsafe & ref
3 participants