make it self-assignment safe
authorKonrad Rosenbaum <konrad@silmor.de>
Mon, 13 Feb 2012 20:30:05 +0000 (21:30 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Mon, 13 Feb 2012 20:30:05 +0000 (21:30 +0100)
dptr.h
dptr_shared.h

diff --git a/dptr.h b/dptr.h
index c74ad22..121aaa4 100644 (file)
--- a/dptr.h
+++ b/dptr.h
@@ -53,5 +53,5 @@ To be used in implementation where the actual d-pointer class is implemented.
  Class::DPrivate::~DPrivate(){delete d;}\
  Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\
  Class::DPrivate& Class::DPrivate::operator=(const Class::DPrivate&dp)\
- {*d=*(dp.d);return *this;}
+ {if(d!=dp.d)*d=*(dp.d);return *this;}
 
index b824194..88dc7a4 100644 (file)
@@ -58,5 +58,5 @@ To be used in implementation where the actual d-pointer class is implemented.
  Class::DPrivate::~DPrivate(){d->detach();}\
  Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\
  Class::DPrivate& Class::DPrivate::operator=(const DPrivate&dp)\
- {d->detach();d=dp.d;d->attach();return *this;}
+ {if(d!=dp.d){d->detach();d=dp.d;d->attach();}return *this;}