RVO is performed on a temporary object that is declared volatile. That seems contradictory with the ISO standards 12.8 15 (object and copy must have the same cv-unqualified type).
With the following piece of code, I was excepting the copy constructor and destructor to be called. struct String { int field; String(); String(int); ~String(); String (const String &); String (volatile const String &); }; String name() { volatile String t(777); return t; } checking !TREE_VOLATILE (r) in finish_function where the named return value optimization is set up fixes the problem. -- Summary: RVO is performed on volatile temporary Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: christian dot bruel at st dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19531