|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-11-09 15:08:28
>From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
>On Sat, 9 Nov 2002 17:14:49 +0100, "Terje Slettebø"
><tslettebo_at_[hidden]> wrote:
>> In any case, the
>>program below detects presence of NRVO, by returning zero, or greater than
>>zero if NRVO is not present.
>Actually it shows whether that optimization is applied in a specific
>example.
True. But it's better than nothing. :) Intel C++ applied the NRVO, even with
all optimisations turned off. In the same way, MSVC 6 did not, regardless of
settings. This test might be used as a rough guide to which compilers
support NRVO, or not.
>You can't infer nothing from the fact that it isn't applied
>though. If you state the problem as: "Can we test whether this
>compiler is capable of doing NRVO", I think the answer is something
>along the lines of "Yes, go looking at the source code" ;-)
The test is very simple:
test_class f()
{
test_class nrv;
return nrv;
}
I think it's safe to say that, if a compiler doesn't apply NRVO here, it's
quite unlikely that it will do it for a more complex example. Therefore,
it's a good chance that this will catch those compilers that do support NRVO
(at least with reasonable optimisation settings, perhaps), and it will tell
which does not.
Some may support it partially, though. For example Intel C++ doesn't ignore
cv-qualifiers (as Daniel Frey pointed out), but the above doesn't test for
that, so it's a "generous" test. :)
You say that you can infer nothing from that it isn't applied. Could you
elaborate on what conditions you think it may be applied, that it doesn't
apply it for the above test? Not to mention any concrete example.
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk