@@ -2820,38 +2820,45 @@ $(GNAME NewExpression):
2820
2820
collected) heap by default.
2821
2821
)
2822
2822
2823
- $(P The `new` *Type* form constructs an instance of a type and default-initializes it.)
2824
- $(P The *Type(NamedArgumentList)* form allows passing either a single initializer
2825
- of the same type, or multiple arguments for more complex types.
2826
- For class types, *NamedArgumentList* is passed to the class constructor.
2827
- For a dynamic array, the argument sets the initial array length.
2828
- For multidimensional dynamic arrays, each argument corresponds to
2829
- an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).)
2823
+ $(P `new T` constructs an instance of type `T` and default-initializes it.
2824
+ The result is:)
2825
+ * `T` when `T` is a reference type (e.g. class, dynamic array,
2826
+ $(DDSUBLINK spec/hash-map, construction_and_ref_semantic, associative array))
2827
+ * `T*` when `T` is a value type (e.g. basic types, structs)
2828
+
2829
+ $(P The $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form allows passing either a single initializer
2830
+ of the same type, or multiple arguments for more complex types:)
2831
+
2832
+ * For class and struct types, *NamedArgumentList* is passed to the constructor.
2833
+ * For a dynamic array, the argument sets the initial array length.
2834
+ * For multidimensional dynamic arrays, each argument corresponds to
2835
+ an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).
2830
2836
2831
2837
$(SPEC_RUNNABLE_EXAMPLE_RUN
2832
2838
---
2833
2839
int* i = new int;
2834
- assert(*i == 0);
2840
+ assert(*i == 0); // int.init
2835
2841
i = new int(5);
2836
2842
assert(*i == 5);
2837
2843
2838
2844
Object o = new Object;
2839
2845
Exception e = new Exception("info");
2840
2846
2841
- auto a = new int[](2);
2847
+ int[] a = new int[](2);
2842
2848
assert(a.length == 2);
2849
+ a = new int[2]; // same, see below
2843
2850
---
2844
2851
)
2845
2852
2846
- $(P The *Type[AssignExpression]* form allocates a dynamic array with
2853
+ $(P The $(INLINE_GRAMMAR *Type[AssignExpression]*) form allocates a dynamic array with
2847
2854
length equal to *AssignExpression*.
2848
- It is preferred to use the *Type(NamedArgumentList)* form when allocating
2855
+ It is preferred to use the $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form when allocating
2849
2856
dynamic arrays instead, as it is more general.)
2850
2857
2851
2858
$(NOTE It is not possible to allocate a static array directly with
2852
2859
`new` (only by using a type alias).)
2853
2860
2854
- $(P The result is a $(DDSUBLINK const3, unique-expressions, unique expression)
2861
+ $(P The result is a $(DDSUBLINK spec/ const3, unique-expressions, unique expression)
2855
2862
which can implicitly convert to other qualifiers:)
2856
2863
2857
2864
---
0 commit comments