This is the mail archive of the gcc@gcc.gnu.org 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]

Re: gcc 3.0.1 & C++ ABI issues



| > There are other parts of the library where I use "return class(args)"
| > counting the compiler to do the right thing (which it used to).
| > I was planning to change them to use the supposed most efficient NRVO, 
| > but now given the news I suppose there is no hurry...
| 
| Hmm?  If writing "return class (args)" is reasonable for the function in
| question, it is no more or less efficient than the NRVO.  The NRVO is most
| useful for more complicated functions.

Oh, sorry I messed up things.  What I had in mind is actually 

  template<typename _Tp>
    inline complex<_Tp>
    operator-(const complex<_Tp>& __x, const _Tp& __y)
    { return complex<_Tp> (__x) -= __y; }

In an old discussion we had on comp.lang.c++.moderated, it was agreed
(if my memory serves me correctly) that if the above is written to use a
local variable,  then it would be more efficient because "return"
will return what -= returns.  Now it didn't make any measurement since
the NRVO is implemented.

[...]

| > | Are you thinking of this:
| > | 
| > |   inline A f (A a) { return a; }
| > | 
| > |   int main ()
| > |   {
| > |     A a1 = f (A ());
| > |   }
| > | 
| > | ?  Currently, this would involve two constructor calls, the default ctor to
| > | construct the parameter and the copy ctor to initialize 'a1'.  It seems
| > | reasonable to elide the copy ctor in this case,
| 
| > Most people expect that.
| 
| > |  but IMO the standard doesn't allow it. 
| 
| > Really?  I think it is allowed: 12.8/15
| 
| >    Whenever a temporary class object is copied using a copy constructor,
| >    and this object and the copy have the same cv-unqualified type, an
| >    implementation is permitted to treat the original and the copy as two
| >    different ways of referring to the same object and not perform a copy
| >    at all, even if the class copy constructor or destructor have side
| >    effects.  [...]
| 
| The copy constructor I see is for copying the parameter 'a' into the return
| value of f.  'a' is not a temporary, it is a parameter

Aha, thanks for the clarification.  But isn't the parameter 'a'
considered a local variable to f for the purpose of expression
evaluation?  Or am I reading too much in the Standard?

-- Gaby


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