[Version 10.0] Feature support for parameterless struct constructors#1561
Draft
RexJaeschke wants to merge 9 commits intodraft-10from
Draft
[Version 10.0] Feature support for parameterless struct constructors#1561RexJaeschke wants to merge 9 commits intodraft-10from
RexJaeschke wants to merge 9 commits intodraft-10from
Conversation
Removed an empty line before the example section in structs.md.
Three passages directly contradict the feature: - **Line 268** — *"it is not possible for a struct type to contain an explicit declaration of a parameterless constructor"* — This prohibition must be replaced with text that permits explicit parameterless constructors, requires them to be public, and cross-references §16.4.9. - **Line 232** — *"All value types implicitly declare a public parameterless instance constructor called the default constructor."* — Needs qualification: this applies only when no explicit parameterless constructor is declared. - **Lines 251–252** — Note claims `default(S)` and `new S()` produce the same result. This is no longer true when a struct has an explicit parameterless constructor with field initializers. Must be qualified: only holds when no explicit parameterless constructor is declared. Rewrite the opening to distinguish synthesized vs. explicit parameterless constructors. Qualify the note. Replace the final paragraph's prohibition with a permissive statement.
Line 298 says: *"Unlike a class, a struct is not permitted to declare a parameterless instance constructor."* — Directly contradicts the feature. Rewrite to say: when a struct does not declare an explicit parameterless constructor, one is synthesized that returns the zeroed value. Note that `default` always produces the zeroed value, while `new S()` invokes the declared constructor when one exists.
The first bullet says for value types with no arguments, the result is *"the default value for `T`"*. When a struct has an explicit parameterless constructor, `new S()` invokes that constructor and the result may differ from the zeroed default value. Changes: Qualify the first bullet: when `T` is a *struct_type* with an explicitly declared parameterless constructor, the expression invokes that constructor (falling through to overload resolution in the third bullet), rather than unconditionally returning the default value.
4cb7baf to
58bc12d
Compare
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.
This is Rex's adaptation of the corresponding MS proposal.