<s>
In	O
C++	B-Language
computer	B-General_Concept
programming	I-General_Concept
,	O
copy	B-Language
elision	I-Language
refers	O
to	O
a	O
compiler	B-Application
optimization	I-Application
technique	O
that	O
eliminates	O
unnecessary	O
copying	O
of	O
objects	O
.	O
</s>
<s>
The	O
C++	B-Language
language	I-Language
standard	O
generally	O
allows	O
implementations	O
to	O
perform	O
any	O
optimization	O
,	O
provided	O
the	O
resulting	O
program	B-Application
's	O
observable	O
behavior	O
is	O
the	O
same	O
as	B-Language
if	I-Language
,	O
i.e.	O
</s>
<s>
pretending	O
,	O
the	O
program	B-Application
were	O
executed	O
exactly	O
as	O
mandated	O
by	O
the	O
standard	O
.	O
</s>
<s>
Beyond	O
that	O
,	O
the	O
standard	O
also	O
describes	O
a	O
few	O
situations	O
where	O
copying	O
can	O
be	O
eliminated	O
even	O
if	O
this	O
would	O
alter	O
the	O
program	B-Application
's	O
behavior	O
,	O
the	O
most	O
common	O
being	O
the	O
return	B-Language
value	I-Language
optimization	O
(	O
see	O
below	O
)	O
.	O
</s>
<s>
Another	O
widely	O
implemented	O
optimization	O
,	O
described	O
in	O
the	O
C++	B-Language
standard	O
,	O
is	O
when	O
a	O
temporary	O
object	O
of	O
class	O
type	O
is	O
copied	O
to	O
an	O
object	O
of	O
the	O
same	O
type	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
copy-initialization	O
is	O
usually	O
equivalent	O
to	O
direct-initialization	O
in	O
terms	O
of	O
performance	O
,	O
but	O
not	O
in	O
semantics	O
;	O
copy-initialization	O
still	O
requires	O
an	O
accessible	O
copy	B-Language
constructor	I-Language
.	O
</s>
<s>
According	O
to	O
the	O
standard	O
a	O
similar	O
optimization	O
may	O
be	O
applied	O
to	O
objects	O
being	O
thrown	B-General_Concept
and	I-General_Concept
caught	I-General_Concept
,	O
but	O
it	O
is	O
unclear	O
whether	O
the	O
optimization	O
applies	O
to	O
both	O
the	O
copy	O
from	O
the	O
thrown	O
object	O
to	O
the	O
exception	O
object	O
,	O
and	O
the	O
copy	O
from	O
the	O
exception	O
object	O
to	O
the	O
object	O
declared	O
in	O
the	O
exception-declaration	O
of	O
the	O
catch	O
clause	O
.	O
</s>
<s>
A	O
conforming	O
compiler	B-Language
should	O
therefore	O
produce	O
a	O
program	B-Application
which	O
prints	O
"	O
Hello	O
World	O
!	O
"	O
</s>
<s>
In	O
the	O
current	O
revision	O
of	O
the	O
C++	B-Language
standard	O
(	O
C++11	B-Language
)	O
,	O
the	O
issues	O
have	O
been	O
addressed	O
,	O
essentially	O
allowing	O
both	O
the	O
copy	O
from	O
the	O
named	O
object	O
to	O
the	O
exception	O
object	O
,	O
and	O
the	O
copy	O
into	O
the	O
object	O
declared	O
in	O
the	O
exception	B-General_Concept
handler	I-General_Concept
to	O
be	O
elided	O
.	O
</s>
<s>
GCC	B-Application
provides	O
the	O
-fno-elide-constructors	O
option	O
to	O
disable	O
copy-elision	O
.	O
</s>
<s>
This	O
option	O
is	O
useful	O
to	O
observe	O
(	O
or	O
not	O
observe	O
)	O
the	O
effects	O
of	O
return	B-Language
value	I-Language
optimization	O
or	O
other	O
optimizations	O
where	O
copies	O
are	O
elided	O
.	O
</s>
<s>
In	O
the	O
context	O
of	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
,	O
return	B-Language
value	I-Language
optimization	O
(	O
RVO	O
)	O
is	O
a	O
compiler	B-Application
optimization	I-Application
that	O
involves	O
eliminating	O
the	O
temporary	O
object	O
created	O
to	O
hold	O
a	O
function	O
's	O
return	B-Language
value	I-Language
.	O
</s>
<s>
RVO	O
is	O
allowed	O
to	O
change	O
the	O
observable	O
behaviour	O
of	O
the	O
resulting	O
program	B-Application
by	O
the	O
C++	B-Language
standard	O
.	O
</s>
<s>
In	O
general	O
,	O
the	O
C++	B-Language
standard	O
allows	O
a	O
compiler	B-Language
to	O
perform	O
any	O
optimization	O
,	O
provided	O
the	O
resulting	O
executable	B-Application
exhibits	O
the	O
same	O
observable	O
behaviour	O
as	B-Language
if	I-Language
(	O
i.e.	O
</s>
<s>
This	O
is	O
commonly	O
referred	O
to	O
as	O
the	O
"	O
as-if	B-Language
rule	I-Language
"	O
.	O
</s>
<s>
The	O
term	O
return	B-Language
value	I-Language
optimization	O
refers	O
to	O
a	O
special	O
clause	O
in	O
the	O
C++	B-Language
standard	O
that	O
goes	O
even	O
further	O
than	O
the	O
"	O
as-if	O
"	O
rule	O
:	O
an	O
implementation	O
may	O
omit	O
a	O
copy	O
operation	O
resulting	O
from	O
a	O
return	B-Language
statement	I-Language
,	O
even	O
if	O
the	O
copy	B-Language
constructor	I-Language
has	O
side	O
effects	O
.	O
</s>
<s>
The	O
following	O
example	O
demonstrates	O
a	O
scenario	O
where	O
the	O
implementation	O
may	O
eliminate	O
one	O
or	O
both	O
of	O
the	O
copies	O
being	O
made	O
,	O
even	O
if	O
the	O
copy	B-Language
constructor	I-Language
has	O
a	O
visible	O
side	O
effect	O
(	O
printing	O
text	O
)	O
.	O
</s>
<s>
The	O
first	O
copy	O
that	O
may	O
be	O
eliminated	O
is	O
the	O
one	O
where	O
a	O
nameless	O
temporary	O
C	O
could	O
be	O
copied	O
into	O
the	O
function	O
f	O
's	O
return	B-Language
value	I-Language
.	O
</s>
<s>
Depending	O
upon	O
the	O
compiler	B-Language
,	O
and	O
that	O
compiler	B-Language
's	O
settings	O
,	O
the	O
resulting	O
program	B-Application
may	O
display	O
any	O
of	O
the	O
following	O
outputs	O
:	O
</s>
<s>
Returning	O
an	O
object	O
of	O
built-in	O
type	O
from	O
a	O
function	O
usually	O
carries	O
little	O
to	O
no	O
overhead	O
,	O
since	O
the	O
object	O
typically	O
fits	O
in	O
a	O
CPU	B-General_Concept
register	I-General_Concept
.	O
</s>
<s>
The	O
function	O
's	O
return	B-Language
value	I-Language
is	O
then	O
copied	O
into	O
the	O
hidden	O
object	O
.	O
</s>
<s>
In	O
the	O
early	O
stages	O
of	O
the	O
evolution	O
of	O
C++	B-Language
,	O
the	O
language	O
's	O
inability	O
to	O
efficiently	O
return	O
an	O
object	O
of	O
class	O
type	O
from	O
a	O
function	O
was	O
considered	O
a	O
weakness	O
.	O
</s>
<s>
Bright	O
implemented	O
this	O
optimization	O
in	O
his	O
Zortech	B-Language
C++	I-Language
compiler	B-Language
.	O
</s>
<s>
This	O
particular	O
technique	O
was	O
later	O
coined	O
"	O
Named	O
return	B-Language
value	I-Language
optimization	O
"	O
(	O
NRVO	O
)	O
,	O
referring	O
to	O
the	O
fact	O
that	O
the	O
copying	O
of	O
a	O
named	O
object	O
is	O
elided	O
.	O
</s>
<s>
Return	B-Language
value	I-Language
optimization	O
is	O
supported	O
on	O
most	O
compilers	B-Language
.	O
</s>
<s>
There	O
may	O
be	O
,	O
however	O
,	O
circumstances	O
where	O
the	O
compiler	B-Language
is	O
unable	O
to	O
perform	O
the	O
optimization	O
.	O
</s>
