http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53990
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|wrong-code |accepts-invalid Status|UNCONFIRMED |RESOLVED Resolution| |INVALID Severity|major |normal --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-07-17 06:00:37 UTC --- >Is this optimization in C++ standard? Yes it is the named return value optimization which is part of the C++ standard. > A[2] = E[1]; //it works. but should it work? This code is valid but most likely does not do what you want it to do. In that it creates a temporary variable (a rvalue) to hold A[2]. Then it calls operator= on that rvalue (which is valid).