If I compile this code: (g++ -o element element.cpp) #include <iostream> #include <string>
using namespace std; class element { public: element() { cout << "element() = " << this << endl; } element(const element &e) { cout << "element(const element &e="<< &e << ") = " << this << endl; } ~element() { cout << "~element() = " << this << endl; } element &operator=(const element &e) { cout << "operator=(const element &e="<< &e << ") = " << this << endl; } string getString() {return a;} private: string a; }; element parse() { element aelement; return aelement; } element parse2() { element aelement; return aelement; } bool toto=true; int main() { element el = toto ? el = parse() : parse2(); return 0; } It compiles without warning or error. However, the result is: element() = 0xfeffc680 operator=(const element &e=0xfeffc680) = 0xfeffc67c element(const element &e=0x8049ea8) = 0xfeffc67c ~element() = 0xfeffc680 ~element() = 0xfeffc67c You can see that operator= is called on a object of address 0xfeffc67c before this object is constructed. Regards, Jean-Baptiste -- Summary: Operator= called on a non constructed object. Product: gcc Version: 4.0.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: wonsjb at gmail dot com GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37911