/* bug.cc */ /* simple program to demonstrate the bug with named return values in gcc */ /* (w) 4.9.97 by Kurt Garloff */ // Special g++ Options: // excess errors test - XFAIL *-*-* #include template class test; template test operator + (const test& a, const test& b); // A simple numerical class template class test { T elem; public: test () { elem = 0; }; test (const T& a) { elem = a; }; test& operator += (const test& a) { elem += a.elem; return *this; }; friend test operator + <> (const test&, const test&); friend ostream& operator << (ostream& os, const test& a) { return os << a.elem; }; }; // named return value version template test operator + (const test& a, const test& b) return c(a); { c += b; }; int main() { test x, y; x += 5; cout << x << endl; y = x + test(2); cout << y << endl; }