[Issue 20752] __traits(isReturnOnStack, func) is incomplete and can't be trusted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 21 17:51:44 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20752

kinke <kinke at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke at gmx.net

--- Comment #2 from kinke <kinke at gmx.net> ---
(In reply to Iain Buclaw from comment #1)
> For finding out if a struct is to be returned using (N)RVO, the right test
> to use would be __traits(isPOD).
> 
> If a struct is non-POD, then it should _always_ be passed around by
> invisible reference, no ifs, no buts, no excuses.
> 
> However, that's ignoring static arrays, which is a little more hairy to find
> out, as they need to be big enough to be considered returning in memory. 
> But just what is "big enough" is a very target-specific question.

That goes for large structs too, not just static arrays, so isPOD is definitely
not sufficient.

The isReturnOnStack trait isn't directly related to NRVO and only depends on
the ABI; in LLVM lingo, passing a pointer to the pre-allocated result is called
sret, struct-return. NRVO just means that a named variable in the callee will
be emplaced into that memory directly, so an sret ABI requirement for the
callee is an orthogonal prerequisite for NRVO to work (in the callee).

--


More information about the Digitalmars-d-bugs mailing list