Why g++ does not enable RVO here?
问题 Consider that TEST code: #include <iostream> using namespace std; class Klass { public: Klass() { cout << "Klass()" << endl; } Klass(const Klass& right) { cout << "Klass(const Klass& right)" << endl; } }; Klass create(Klass a) { cout << "create(Klass a)" << endl; return a; } int main() { const Klass result = create(Klass()); } Compiling with: g++ -O3 rvo.cpp -o rvo The output is: $ ./rvo Klass() create(Klass a) Klass(const Klass& right) I was expecting the compiler to use the RVO mechanism in