Skip to content

[Version 10.0] Feature support for parameterless struct constructors#1561

Draft
RexJaeschke wants to merge 9 commits intodraft-10from
v10-parameterless-struct-constructors
Draft

[Version 10.0] Feature support for parameterless struct constructors#1561
RexJaeschke wants to merge 9 commits intodraft-10from
v10-parameterless-struct-constructors

Conversation

@RexJaeschke
Copy link
Contributor

This is Rex's adaptation of the corresponding MS proposal.

@RexJaeschke RexJaeschke added this to the C# 10 milestone Jan 30, 2026
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Jan 30, 2026
@RexJaeschke RexJaeschke marked this pull request as draft January 30, 2026 18:24
RexJaeschke and others added 8 commits March 26, 2026 11:11
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.
@BillWagner BillWagner force-pushed the v10-parameterless-struct-constructors branch from 4cb7baf to 58bc12d Compare March 26, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants