U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » Unsafe Deep Copy
Unsafe Deep Copy [message #8787] Sat, 31 March 2007 12:11 Go to next message
victorb is currently offline  victorb
Messages: 78
Registered: December 2005
Location: Nice, France
Member
I think there might be an issue with the following code

template <class T, class B = EmptyClass>
class DeepCopyOption : public B {
public:
	friend T& operator<<=(T& dest, const T& src)
	{ (&dest)->T::~T(); ::new(&dest) T(src, 1); return dest; }
        ...
};


The issue occurs when you are self deep copying :
a <<= a;

One solution is
	friend T& operator<<=(T& dest, const T& src)
	{ if (&src != &dest) {(&dest)->T::~T(); ::new(&dest) T(src, 1);} return dest; }
Re: Unsafe Deep Copy [message #8790 is a reply to message #8787] Sat, 31 March 2007 17:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Thanks.

Mirek
Re: Unsafe Deep Copy [message #8791 is a reply to message #8790] Sat, 31 March 2007 18:00 Go to previous message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
PS.: As this is not too serious flaw, I have fixed it in newcore only...

Mirek
Previous Topic: XmlIO - New function proposal
Next Topic: StrDbl and decimal separator
Goto Forum:
  


Current Time: Sun May 10 06:18:47 GMT+2 2026

Total time taken to generate the page: 0.00679 seconds