-
-
Notifications
You must be signed in to change notification settings - Fork 667
Open
Description
This is no news, but IMO the fix of #22297 will depend on how structs in static arrays are specified to behave. There is no such specification ATM.
Postblits do work however.
struct S
{
int i;
this(int i) { this.i = i; }
this(ref S s) { s.i = i; }
this(S s) { s.i = 0; }
~this() { i = 0; }
}
struct T
{
S s;
// Uncomment to make line 33 pass
// this(S s) { this.s = s; }
static T make(S s) => T(s);
}
ref S move(ref S s) __rvalue => s;
T f(ref S s) => T.make(move(s));
T g(ref S s) => T(move(s));
S[1] h(ref S s) => [move(s)];
void main()
{
// Works if a function call takes S by value
S s1 = S(1);
f(s1);
assert(s1.i == 0);
// Does not work with a struct literal, unless line 14 is uncommented
S s2 = S(1);
g(s2);
assert(s2.i == 0);
// Nor with a static array
S s3 = S(1);
h(s3);
assert(s3.i == 0);
}Metadata
Metadata
Assignees
Labels
No labels