The NG server was down when I submitted this to Bugzilla and it's a pretty important issue, so I'm posting it to the NG manually now:

import core.stdc.stdio;

struct S {
    this(this) {

    ~this() {

S doIt(int i) {
    S s1;
    S s2;
    printf("s1 lives at %p.\n", &s1);
    printf("s2 lives at %p.\n", &s2);
    return (i == 42) ? s1 : s2;

void main() {
    auto s = doIt(3);
    printf("s lives at %p.\n", &s);


s1 lives at 0xffc54368.
s2 lives at 0xffc54369.
s lives at 0xffc5437c.

Both D'tors are called and the returned result lives at a different address
after being returned than before, as expected if not using NRVO. On the other hand, no postblit being called for whichever struct is returned, as expected if
using NRVO.

Reply via email to