This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: missing optimization - don't compute return value not used?
Right, page 211 of the C++ standard (2003) explains when copy-ctor and
dtor are allowed to be optimized away. But the two circumstances are
both like this:
A is constructed; A is copy-constructed to B; A is destructed
Here A is a temporary object in some sense, and the standard allows
for directly constructing B.
However, Neal expected the compiler to optimize "A is constructed; A
is destructed" away. I find nowhere in the standard that allows this.
ps, Did you forget to put gcc@gcc.gnuorg in the cc list?
On 9/26/07, Michael Veksler <mveksler@tx.technion.ac.il> wrote:
> But, according to the C++ standard, the compiler is allowed to optimize
> copy construction away. GCC does that in many occasions . For example try:
> |
> #include <iostream>
> using namespace std;
> struct T {
> T() { }
> T(const T&) { cout << "!!! copy ctor !!! \n"; }
> };
> T f() { T t; return t;}
> int main()
> {
> cout << "No copy\n";
> T no_copy= f();
>
> cout << "Expecting copy\n";
> T copy= no_copy;
> }
> |