Skip to content

Commit 58bc12d

Browse files
committed
binding resolution fixes
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.
1 parent 008dcb6 commit 58bc12d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

standard/expressions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,8 @@ If any of the arguments in the optional *argument_list* has the compile-time typ
26352635
The binding-time processing of an *object_creation_expression* of the form `new T(A)`, where the specified or implied type `T` is a *class_type*, or a *value_type*, and `A` is an optional *argument_list*, consists of the following steps:
26362636

26372637
- If `T` is a *value_type* and `A` is not present:
2638-
- The *object_creation_expression* is a default constructor invocation. The result of the *object_creation_expression* is a value of type `T`, namely the default value for `T` as defined in [§8.3.3](types.md#833-default-constructors).
2638+
- If `T` is a *struct_type* that has an explicitly declared parameterless instance constructor, that constructor is a candidate and is selected via overload resolution as described below.
2639+
- Otherwise, the *object_creation_expression* is a default constructor invocation. The result of the *object_creation_expression* is a value of type `T`, namely the default value for `T` as defined in [§8.3.3](types.md#833-default-constructors).
26392640
- Otherwise, if `T` is a *type_parameter* and `A` is not present:
26402641
- If no value type constraint or constructor constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)) has been specified for `T`, a binding-time error occurs.
26412642
- The result of the *object_creation_expression* is a value of the run-time type that the type parameter has been bound to, namely the result of invoking the default constructor of that type. The run-time type may be a reference type or a value type.

0 commit comments

Comments
 (0)