You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A "`scope` value" is the value of a `scope` variable, or any generated value that is (or could be) allocated on the stack:
736
+
$(UL
737
+
$(LI The address of a function local variable / parameter)
738
+
$(LI A struct member accessed through the implicit `this` parameter)
739
+
$(LI The return value of a $(DDSUBLINK spec/function, ref-functions, Ref Function))
740
+
$(LI The variadic parameter from $(DDSUBLINK spec/function, typesafe_variadic_functions, Typesafe Variadic Functions))
741
+
)
742
+
743
+
When a local variable is assigned a `scope` value, it is inferred `scope`, even when the variable has an explicit type and does not use the `auto` keyword.
744
+
)
745
+
746
+
---
747
+
int* escape(ref int x, int y, scope int* z)
748
+
{
749
+
scope int* w;
750
+
751
+
auto xPtr = &x; // inferred `scope int*`
752
+
int* yPtr = &y; // also inferred `scope int*`
753
+
int* zCopy = z; // inferred `scope int*`
754
+
int* wCopy = w; // inferred `scope int*`
755
+
756
+
return yPtr; // error
757
+
}
758
+
759
+
void variadic(int[] a...)
760
+
{
761
+
int[] x = a; // inferred `scope int[]`
762
+
}
763
+
764
+
struct S
765
+
{
766
+
int x;
767
+
768
+
// this method may be called on a stack-allocated instance of S
769
+
void f()
770
+
{
771
+
int* p = &x; // inferred `scope int* p`
772
+
int* q = &this.x; // equivalent
773
+
}
774
+
}
775
+
---
776
+
777
+
$(P
778
+
$(DDSUBLINK spec/function, scope-parameters, scope parameters) are treated the same as scope local variables,
779
+
except that returning them is allowed when the function has $(DDSUBLINK spec/function, function-attribute-inference, Function Attribute Inference).
780
+
In that case, they are inferred as $(DDSUBLINK spec/function, return-scope-parameters, return scope parameters).
781
+
)
782
+
714
783
$(H3 $(LNAME2 scope-class-var, $(D scope) variables with `class` type))
715
784
$(P
716
785
When used on variables with a `class` type, `scope` signifies the RAII
0 commit comments