I am trying to understand why a reasonably good C ++ 11 compiler (clang) does not optimize this code and wonders if anyone has opinions.
#include <iostream>
If I run it with #define SLOW commented out and optimized with -s , I get
Hello World! A move A d'tor 0x7fff5fbff9f0 A d'tor
which is expected.
If I run this with #define SLOW enabled and optimized with -s , I get:
Hello World! A copy A move A d'tor A d'tor 0x7fff5fbff9e8 A d'tor
Which is clearly not so good. So the question is:
Why can't I see the NRVO optimization used in the case of "SLOW"? I know that the compiler should not use NRVO, but this would seem to be such a simple simple case.
In general, I try to encourage the SLOW style code because it is much easier for me to debug it.
c ++ optimization c ++ 11 nrvo
dmaclach
source share