From e260e62ddaefa0db5226f88313d30d5b50182d3a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 3 Oct 2007 00:48:55 +0000 Subject: [PATCH] Fixed bug where intrusive_ptr_add_ref and intrusive_ptr_release were not declared "static inline." Removed member templates for operator= and copy constructor. They simply didn't work as expected. Fixed reference counting bug when a smart pointer is assigned the value of another smart pointer that refers to the same address. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42562 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/Support/IntrusiveSPtr.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/include/clang/Analysis/Support/IntrusiveSPtr.h b/include/clang/Analysis/Support/IntrusiveSPtr.h index 100e3dee9b..4c0322ef8a 100644 --- a/include/clang/Analysis/Support/IntrusiveSPtr.h +++ b/include/clang/Analysis/Support/IntrusiveSPtr.h @@ -64,11 +64,11 @@ protected: /// particular naming was chosen to be compatible with /// boost::intrusive_ptr, which provides similar functionality to /// IntrusiveSPtr. -void intrusive_ptr_add_ref(clang::RefCounted* p) { p->Retain(); } +static inline void intrusive_ptr_add_ref(clang::RefCounted* p) { p->Retain(); } /// intrusive_ptr_release - The complement of intrusive_ptr_add_ref; /// decrements the reference count of a RefCounted object. -void intrusive_ptr_release(clang::RefCounted* p) { p->Release(); } +static inline void intrusive_ptr_release(clang::RefCounted* p) { p->Release(); } namespace clang { @@ -97,14 +97,7 @@ public: retain(); } - template - IntrusiveSPtr(const IntrusiveSPtr& S) { - Obj = static_cast(const_cast(S.getPtr())); - retain(); - } - - template - IntrusiveSPtr& operator=(const IntrusiveSPtr& S) { + IntrusiveSPtr& operator=(const IntrusiveSPtr& S) { replace(static_cast(S.getPtr())); return *this; } @@ -127,7 +120,10 @@ private: void retain() { if (Obj) intrusive_ptr_add_ref(Obj); } void release() { if (Obj) intrusive_ptr_release(Obj); } - void replace(const T* o) { + void replace(const T* o) { + if (o == Obj) + return; + release(); Obj = const_cast(o); retain(); -- 2.40.0