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]
Other format: [Raw text]

Re: Temporary object omits constructor


On Wed, 2008-05-21 at 10:32 -0700, Joe Buck wrote:
> You forgot to add
> 
> A::A(const A&) { ++c;}
> 
> The missing call is to the copy constructor.  Since you didn't declare
> one, the compiler inserts one, and it doesn't increment the counter.

Arghl your right. I removed the copy constructor two test cases before
and forget to add it again.

> Also, there are situations where a C++ compiler is allowed to eliminate
> temporaries (even if this changes side effects that are invoked by
> a copy constructor).

Yes your right. C++ Standard 12.8/15 says the same. But the object has
to be cv-unqualified and/or unnamed.

Thanks for your hint!

Best regards
Stefan


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