@@ -2371,9 +2371,44 @@ $(GNAME ArgumentList):
2371
2371
collected) heap.
2372
2372
)
2373
2373
2374
- $(P If a $(I NewExpression) is used as an initializer for
2374
+ $(P The *Type* form constructs an instance of a type and default-initializes it.)
2375
+ $(P The *Type(ArgumentList)* form allows passing either a single initializer
2376
+ of the same type, or multiple arguments for more complex types.
2377
+ For class types, *ArgumentList* is passed to the class constructor.
2378
+ For a dynamic array, the argument sets the initial array length.
2379
+ For multidimensional dynamic arrays, each argument corresponds to
2380
+ an initial length.)
2381
+
2382
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
2383
+ ---
2384
+ int* i = new int;
2385
+ assert(*i == 0);
2386
+ i = new int(5);
2387
+ assert(*i == 5);
2388
+
2389
+ Object o = new Object;
2390
+ Exception e = new Exception("info");
2391
+
2392
+ auto a = new int[](2);
2393
+ assert(a.length == 2);
2394
+
2395
+ int[][] m = new int[][](10, 5);
2396
+ assert(m.length == 10);
2397
+ assert(m[0].length == 5);
2398
+ ---
2399
+ )
2400
+
2401
+ $(P The *Type[AssignExpression]* form allocates a dynamic array with
2402
+ length equal to *AssignExpression*.
2403
+ It is preferred to use the *Type(ArgumentList)* form when allocating
2404
+ dynamic arrays instead, as it is more general.)
2405
+
2406
+ $(NOTE It is not possible to allocate a static array directly with
2407
+ `new` (only by using a type alias).)
2408
+
2409
+ $(P If a $(I NewExpression) is used with a class type as an initializer for
2375
2410
a function local variable with $(DDSUBLINK spec/attribute, scope, `scope`) storage class,
2376
- then the instance is allocated on the stack.
2411
+ then the instance is $(DDSUBLINK spec/attribute, scope-class-var, allocated on the stack) .
2377
2412
)
2378
2413
2379
2414
$(P `new` can also be used to allocate a
0 commit comments