]> granicus.if.org Git - clang/commitdiff
Fixed bug where intrusive_ptr_add_ref and intrusive_ptr_release were
authorTed Kremenek <kremenek@apple.com>
Wed, 3 Oct 2007 00:48:55 +0000 (00:48 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 3 Oct 2007 00:48:55 +0000 (00:48 +0000)
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

index 100e3dee9b4bc7dfbc3b121087924c043a07d5fa..4c0322ef8a3900a6d100a8c2c4f5fa1737fb0d39 100644 (file)
@@ -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 <typename X>
-  IntrusiveSPtr(const IntrusiveSPtr<X>& S) {
-    Obj = static_cast<T*>(const_cast<X*>(S.getPtr()));
-    retain();
-  }
-  
-  template <typename X>
-  IntrusiveSPtr& operator=(const IntrusiveSPtr<X>& S) {
+  IntrusiveSPtr& operator=(const IntrusiveSPtr& S) {
     replace(static_cast<const T*>(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<T*>(o);
     retain();