[dmd-internals] NRVO tests check for essentially undefined behaviour

Iain Buclaw ibuclaw at gdcproject.org
Sat Dec 9 14:01:59 UTC 2017


There are a number of NRV tests in the testsuite that do pointer
comparison on what would otherwise be undefined behaviour.

For instance:
---
/**********************************/
// 13089

struct S13089
{
    @disable this(this);    // non nothrow
}

void* p13089;

S13089[1000] foo13089() nothrow
{
    typeof(return) data;
    p13089 = &data;
    return data;
}

void test13089()
{
    immutable data = foo13089();
    assert(p13089 == &data);
}
---

What 'p13089' points to after the scope of 'foo13089' closes is
undefined, and NRV does not give us any semantic guarantee about what
this code should do.

There should be better ways to validate that NRVO is happening.  I
could perhaps put these in a new test file under runnable/testnrvo.d

Iain.


More information about the dmd-internals mailing list