[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 15:55:00 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20752
Iain Buclaw <ibuclaw at gdcproject.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ibuclaw at gdcproject.org
--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to Mathias LANG from comment #0)
> Since half of the logic for NRVO is in the backend, this traits simply
> cannot be relied on and is mostly useless.
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.
> For example, the following compiles and triggers the assert with DMD:
>
[--snip--]
>
> I would expect a compilation error, or the assert to pass.
Worse, some back-ends can't provide any useful information as there's no access
to "target". This is from the gdc-ddmd branch with included explanation.
---
bool
Target::isReturnOnStack (TypeFunction *, bool)
{
/* Need the back-end type to determine this, but this is called from the
frontend before semantic processing is finished. An accurate value
is not currently needed anyway. */
return true;
}
---
A type could be synthesized, however. But it would be a best guess approach.
--
More information about the Digitalmars-d-bugs
mailing list