fix Issue 20567 returning the result of a constructor should be NRVO (#20568)

This commit is contained in:
Walter Bright 2024-12-18 00:48:52 -08:00 committed by GitHub
parent 85fe931daa
commit b7a3a1942c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 53 additions and 19 deletions

View file

@ -22,9 +22,35 @@ void test1()
assert(&r == s1ptr);
}
/***************************************************/
// https://github.com/dlang/dmd/issues/20567
struct S2
{
int x;
this(ref S2 s) { x = s.x; }
}
S2 returnRval(ref S2 arg1, ref S2 arg2, int i)
{
return i ? arg1 : arg2;
}
void test2()
{
S2 s1, s2;
s1.x = 3;
s2.x = 4;
S2 s = returnRval(s1, s2, 0);
assert(s.x == 4);
s = returnRval(s1, s2, 1);
assert(s.x == 3);
}
/***************************************************/
void main()
{
test1();
test2();
}