mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
fix Issue 20567 returning the result of a constructor should be NRVO (#20568)
This commit is contained in:
parent
85fe931daa
commit
b7a3a1942c
10 changed files with 53 additions and 19 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue