This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/29378] The copy constructor is not being called upon return from function calls.

------- 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

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]