------- Comment #2 from SSacek at appsecinc dot com  2006-10-07 09:19 -------
Ok, I see that GCC has a work-around for this issue, but I must insist that the
GCC compiler is incorrect in its interpretation of the C++ standard for two
reasons.

1) Optimizations should be allowed for temporary objects only, but not for
named (permanent) objects. Example:

   struct S{};

   S foo()
   {
      return S; // this is an un-named temporary object
                // optimizations allowed
   }

   S foo2()
   {
      S s1;      // this is a named permanent object
      return s1; // optimizations not allowed
   }

   The object in foo2() is permanent, and lives and dies in the scope of
function foo2(). Therefore, upon return, the copy constructor must be called,
as well as the destructor.


2) The second reason is that if GCC ignores the programmer written copy
constructors, then the program will be misbehaved, and the results
unpredictable, with even the possibility of a crash. Optimizations are
understandable only if they don't leave objects in unknown states.

The key question here is "WHAT IS A TEMPORARY OBJECT" ?

I am convinced that the GCC compiler has it wrong, and I have the Solaris and
Microsoft compilers to back me up on this. 

Just how many C++ Standards are there?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29378

Reply via email to