diff --git a/changelog/2.110.0_pre.dd b/changelog/2.110.0_pre.dd index ed2cb3eb19..4997b1bff3 100644 --- a/changelog/2.110.0_pre.dd +++ b/changelog/2.110.0_pre.dd @@ -88,6 +88,13 @@ $(P ) ) +$(LI $(LNAME2 dmd.enable-rvaluerefparam,Enabled -preview=rvaluerefparam after a long testing period.) +$(CHANGELOG_SOURCE_FILE dmd, changelog/dmd.enable-rvaluerefparam.dd) +$(P +You can now supply an rvalue to a ref argument. A temporary will automatically be created for the call. +) +) + ) @@ -189,6 +196,7 @@ $(D_CONTRIBUTORS $(D_CONTRIBUTOR Jeremy Baxter) $(D_CONTRIBUTOR Johan Engelen) $(D_CONTRIBUTOR Jonathan M Davis) + $(D_CONTRIBUTOR Manu Evans) $(D_CONTRIBUTOR Martin Kinkelin) $(D_CONTRIBUTOR Mathias Lang) $(D_CONTRIBUTOR Nicholas Wilson) diff --git a/spec/function.dd b/spec/function.dd index 7bf81d2d52..0f57e1a37e 100644 --- a/spec/function.dd +++ b/spec/function.dd @@ -409,7 +409,6 @@ $(H2 $(LNAME2 function-return-values, Function Return Values)) $(P Function return values not marked as $(RELATIVE_LINK2 ref-functions, `ref`) are considered to be rvalues. - This means they cannot be passed by reference to other functions. ) $(H2 $(LNAME2 pure-functions, Pure Functions)) @@ -1538,8 +1537,6 @@ $(H3 $(LNAME2 in-params, In Parameters)) When not in use, `in` is equivalent to `const`.) $(P The parameter is an input to the function. Input parameters behave as if they have the $(D const scope) storage classes. Input parameters may also be passed by reference by the compiler.) - $(P Unlike $(D ref) parameters$(COMMA) $(D in) parameters can bind to both lvalues and rvalues - (such as literals).) $(P Types that would trigger a side effect if passed by value (such as types with copy constructor$(COMMA) postblit$(COMMA) or destructor)$(COMMA) and types which cannot be copied (e.g. if their copy constructor is marked as $(D @disable)) will always be passed by reference. @@ -1553,9 +1550,8 @@ $(H3 $(LNAME2 in-params, In Parameters)) $(H3 $(LNAME2 ref-params, Ref and Out Parameters)) - $(P By default, parameters take rvalue arguments. - A `ref` parameter takes an lvalue argument, so changes to its value will operate - on the caller's argument.) + $(P A `ref` parameter receives an lvalue reference to the caller's argument, so changes to its value will operate + on the caller's value.) $(SPEC_RUNNABLE_EXAMPLE_RUN --- @@ -1609,6 +1605,10 @@ $(H3 $(LNAME2 ref-params, Ref and Out Parameters)) apply only to the reference and not the contents. ) + $(P If the caller supplies an rvalue (ie; a literal or enum), a temporary is created on the caller's stack and passed by reference. + The temporary is destroyed by the caller immediately after the function completes. + ) + $(H3 $(LNAME2 lazy-params, Lazy Parameters)) $(P An argument to a $(D lazy) parameter is not evaluated before the function is called. diff --git a/spec/glossary.dd b/spec/glossary.dd index 66d4c85da3..63e7173ab8 100644 --- a/spec/glossary.dd +++ b/spec/glossary.dd @@ -234,8 +234,7 @@ void test() $(DD An rvalue is an abstract term referring to a value resulting from an expression that has no accessible memory address. This lack of address is only conceptual; the implementation has the liberty to store an rvalue in - addressable memory. Rvalues cannot be changed and cannot be passed to (or - be returned from) functions by reference. An rvalue is the counterpart to + addressable memory. Rvalues cannot be changed. An rvalue is the counterpart to an lvalue. )