[Issue 7516] Postblit not called for structs returned from a ternary operator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 10 22:55:35 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7516
--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> 2012-05-10 22:56:59 PDT ---
Test cases:
void main()
{
static struct S
{
int val;
this(int n) { val = n; }
this(this) { val *= 3; }
}
// cond ? lvalue : lvalue
S foo(bool f)
{
auto s1 = S(1), s2 = S(2);
return f ? s1 : s2;
}
auto s1 = foo(true);
assert(s1.val == 3);
auto s2 = foo(false);
assert(s2.val == 6);
// cond ? rvalue : rvalue
S bar(bool f)
{
return f ? S(1) : S(2);
}
auto s3 = bar(true);
assert(s3.val == 1);
auto s4 = bar(false);
assert(s4.val == 2);
// cond ? lvalue : rvalue
S baz(bool f)
{
auto s1 = S(1);
return f ? s1 : S(2);
}
auto s5 = baz(true);
assert(s5.val == 3);
auto s6 = baz(false);
assert(s6.val == 2);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list