https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103040

--- Comment #3 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
The test is trivially translatable into C++, though I don't think C++ attempts
to ensure (n)rvo always occurs.

---
#include <assert.h>

struct S101273
{
    int x;
    S101273* impl;
    S101273(int x)
    {
        this->x = x;
        this->impl = this;
    }
    ~S101273() { }
};

S101273 makeS101273()
{
    return S101273(2);
}

S101273 nrvo101273()
{
    S101273 ret = makeS101273();
    return ret;
}

S101273 rvo101273()
{
    return makeS101273();
}

int main()
{
    auto nrvo = nrvo101273();
    assert(&nrvo == nrvo.impl);

    auto rvo = rvo101273();
    assert(&rvo == rvo.impl);

    return 0;
}

Reply via email to