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

> On 14 mar, 21:30, "Amadeus W.M." <[EMAIL PROTECTED]> 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;
}
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus
  • nrvo Amadeus W.M.
    • Re: nrvo Pedro LamarĂ£o
      • Re: nrvo Amadeus W.M.

Reply via email to