Skip to content

Commit c2a58ec

Browse files
authored
Added __rvalue function attribute to the spec. (#4183)
1 parent 100ac62 commit c2a58ec

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spec/attribute.dd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $(GNAME Attribute):
3030
$(RELATIVE_LINK2 override, $(D override))
3131
$(RELATIVE_LINK2 ref, $(D ref))
3232
$(RELATIVE_LINK2 return, $(D return))
33+
$(RELATIVE_LINK2 __rvalue, $(D __rvalue))
3334
$(RELATIVE_LINK2 scope, $(D scope))
3435
$(RELATIVE_LINK2 shared, $(D shared))
3536
$(RELATIVE_LINK2 static, $(D static))
@@ -733,6 +734,10 @@ $(H2 $(LNAME2 return, $(D return) Attribute))
733734
* $(DDSUBLINK spec/function, return-ref-parameters, Return Ref Parameters).
734735
* $(DDSUBLINK spec/function, return-scope-parameters, Return Scope Parameters).
735736

737+
$(H2 $(LNAME2 __rvalue, $(D __rvalue) Attribute))
738+
739+
* $(DDSUBLINK spec/expression, __rvalue-function-attribute, $(I RvalueExpression)).
740+
736741
$(H2 $(LNAME2 static, $(D static) Attribute))
737742

738743
$(P The $(D static) attribute applies to types, functions and data.

spec/expression.dd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,6 +3596,23 @@ void oops()
35963596

35973597
$(P $(I RvalueExpression)s enable the use of $(I move constructor)s and $(I move assignment)s.)
35983598

3599+
$(H4 $(LNAME2 __rvalue-function-attribute, As a function attribute))
3600+
3601+
$(P It is also allowed to use the $(CODE __rvalue) keyword as a function attribute. The presence of this
3602+
attribute will infer the $(I RvalueExpression) upon the function call expression at the call-site,
3603+
as if applied to the function's return value. This is only accepted on functions that return by reference.
3604+
)
3605+
3606+
---
3607+
ref S fun(return ref S s) __rvalue
3608+
{
3609+
return s;
3610+
}
3611+
3612+
S s;
3613+
S t = fun(s); // call inferred as: __rvalue(fun(s))
3614+
---
3615+
35993616
$(H3 $(LNAME2 specialkeywords, Special Keywords))
36003617

36013618
$(GRAMMAR

0 commit comments

Comments
 (0)