Skip to content

Commit bd48508

Browse files
ntreldkorpel
andauthored
[spec/memory-safe-d] Improve return attribute docs (#3878)
* [spec/memory-safe-d] Improve `return` attribute docs Fix Bugzilla 24659 - Memory safe D page lacks information on return ref. Reword `return scope` docs (before this was just listed as `return`). Move sentence about constructor `return` attribute after method attribute. * 'indicate' grammar Co-authored-by: Dennis <[email protected]> * `this` is considered the first parameter * `return` can't appear after free function parameter list --------- Co-authored-by: Dennis <[email protected]>
1 parent 16bd757 commit bd48508

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

spec/memory-safe-d.dd

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,33 @@ $(H2 $(LNAME2 usage, Usage))
5959
passed to functions. Such pointers include: raw pointers, arrays, `this`, classes, `ref` parameters, delegate/lazy parameters,
6060
and aggregates containing a pointer.)
6161

62+
$(P The $(DDSUBLINK spec/function, return-ref-parameters, `return ref`) attributes on a parameter indicate:)
63+
64+
* A pointer derived from the parameter's address may be returned from the function
65+
(e.g. returning the parameter by reference).
66+
* A pointer derived from the parameter's address may be stored in the first parameter of
67+
a function returning `void`, *iff* the first parameter is `ref`.
68+
The `this` reference is considered the first parameter of a method.
69+
6270
$(P $(D scope) ensures that no references to the pointed-to object are retained, in global variables or pointers passed to the
6371
function (and recursively to other functions called in the function), as a result of calling the function.
6472
Variables in the function body and parameter list that are `scope` may have their allocations elided as a result.)
6573

66-
$(P $(D return) indicates that either the return value of the function or the first parameter is a pointer derived from the
67-
`return` parameter or any other parameters also marked `return`.
68-
For constructors, `return` applies to the (implicitly returned) `this` reference.
69-
For void functions, `return` applies to the first parameter $(I iff) it is `ref`; this is to support UFCS,
74+
$(P The $(DDSUBLINK spec/function, return-scope-parameters, `return scope`) attributes on a parameter indicate:)
75+
76+
* A pointer derived from that parameter may be returned from the function.
77+
* A pointer derived from that parameter may be stored in the first parameter of
78+
a function returning `void`, *iff* the first parameter is `ref`.
79+
The `this` reference is considered the first parameter of a method.
80+
81+
$(RATIONALE The second case is to support UFCS,
7082
property setters and non-member functions (e.g. `put` used like `put(dest, source)`).)
7183

72-
$(P These attributes may appear after the formal parameter list, in which case they apply either to a method's `this` parameter, or to
73-
a free function's first parameter $(I iff) it is `ref`.
74-
`return` or `scope` is ignored when applied to a type that is not a low-level pointer.)
84+
$(P These attributes may appear after the formal parameter list of a method,
85+
in which case they apply to the `this` reference.
86+
For constructors, `return` applies to the (implicitly returned) `this` reference.)
87+
88+
$(P `return` or `scope` is ignored when applied to a type that is not a low-level pointer.)
7589

7690
$(P $(B Note:) Checks for `scope` parameters are currently enabled
7791
only for `@safe` code compiled with the `-dip1000` command-line flag.)

0 commit comments

Comments
 (0)