Skip to content

Commit 0462dcf

Browse files
authored
Fixed issue 18830 - document "new" with "scope" in @nogc Functions (#3515)
Fixed issue 18830 - document "new" with "scope" in @nogc Functions Signed-off-by: Razvan Nitu <[email protected]> Merged-on-behalf-of: Razvan Nitu <[email protected]>
1 parent 7c28ebd commit 0462dcf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spec/function.dd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,9 @@ $(H2 $(LNAME2 nogc-functions, No-GC Functions))
35583558
$(LI $(DDSUBLINK spec/expression, AssocArrayLiteral, constructing an associative array))
35593559
$(LI $(DDSUBLINK spec/expression, IndexExpression, indexing) an associative array
35603560
$(NOTE because it may throw $(D RangeError) if the specified key is not present))
3561-
$(LI $(DDSUBLINK spec/expression, NewExpression, allocating an object with `new`) on the heap)
3561+
$(LI $(DDSUBLINK spec/expression, NewExpression, allocating an object with `new`) on the heap
3562+
$(NOTE `new` declarations of $(D class types) in function scopes are compatible with
3563+
$(D @nogc) if used for $(D scope) variables, as they result in allocations on the stack))
35623564
$(LI calling functions that are not `@nogc`, unless the call is
35633565
in a $(GLINK2 version, ConditionalStatement)
35643566
controlled by a $(GLINK2 version, DebugCondition))
@@ -3576,6 +3578,7 @@ $(H2 $(LNAME2 nogc-functions, No-GC Functions))
35763578
aa["abc"]; // (6) error, indexing may allocate and throws
35773579

35783580
auto p = new int; // (7) error, operator new allocates
3581+
scope auto p = new GenericClass(); // (7) Ok
35793582
bar(); // (8) error, bar() may allocate
35803583
debug bar(); // (8) Ok
35813584
}

0 commit comments

Comments
 (0)