help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nrvo


From: Amadeus W.M.
Subject: Re: nrvo
Date: Thu, 15 Mar 2007 13:23:50 +0000 (UTC)
User-agent: Pan/0.125 (Potzrebie)

On Wed, 14 Mar 2007 18:42:59 -0700, Pedro LamarĂ£o
wrote:

> On 14 mar, 21:30, "Amadeus W.M." <amadeu...@verizon.net> wrote:
>> For theoretical purposes, how do I turn off NRVO behavior in g++? I
>> couldn't find anything relevant in the man page.
> 
> Have you tried turning optimization off with -O0 ? That should do it.
>

It doesn't seem to. I compile the following code with g++ -g -Wall -O0. 

#include <iostream>
#include <cstdlib>

using namespace std;

class A
{
public:
    A(double a=0) : x(a) { cerr << "ctor: " << x << endl; };
    A(const A & a) : x(a.x) { cerr << "cpy ctor: " << x << endl; }

    double x;
};


A foobar(double x)
{
    A a(x);
    return a;
}


int main(int argc, char * argv[])
{
    A b = foobar(20); // step inside foobar and see that &a = &b.
    return 0;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]