In the concurrency package I am relying on RVO being performed, essentially I want to ensure placement of a struct on the callee's stack. I am aware I cannot get 100% guarantee of RVO since the compiler is free to perform a blit anywhere it likes.
Regardless, I have tests that ensure it applies RVO. It works fine on all 3 compilers until I turn on DMD's -inline.
I am aware RVO isn't guaranteed to be performed, but since it works fine without inlining, I suspect there is something afoul there (since, by definition, if it is inlined it need not blit anymore).
As a workaround I am using NVRO.
---
struct S {
@disable this(ref return scope typeof(this) rhs);
@disable this(this);
void* cons;
this(int i) {
cons = cast(void*)&this;
}
void start() {
void* s = cast(void*)&this;
assert(cons == s); // fails on dmd when build with -inline
}
}
auto fun() {
// auto s = S(42); // NVRO does work though...
// return s;
return S(42);
}
void main() {
auto op = fun();
op.start();
}
---
Comment #1 by robert.schadek — 2024-12-13T19:17:23Z