Allow a client to clear an IntrustiveRefCntPtr (deliberately leaking the referenced...
[oota-llvm.git] / include / llvm / ADT / IntrusiveRefCntPtr.h
index 8804f2b20f77d788eeceea22049a57d3b832ec0a..f195fb1de8a3b8b382489af9d96d1c671def536b 100644 (file)
@@ -1,4 +1,4 @@
-//== llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer ----*- C++ -*-==//
+//== llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer ---*- C++ -*-==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -64,7 +64,6 @@ namespace llvm {
 ///  inherit from RefCountedBaseVPTR can't be allocated on stack -
 ///  attempting to do this will produce a compile error.
 //===----------------------------------------------------------------------===//
-  template <class Derived>
   class RefCountedBaseVPTR {
     unsigned ref_cnt;
 
@@ -78,7 +77,8 @@ namespace llvm {
       if (--ref_cnt == 0) delete this;
     }
 
-    friend class IntrusiveRefCntPtr<Derived>;
+    template <typename T>
+    friend class IntrusiveRefCntPtr;
   };
 
 //===----------------------------------------------------------------------===//
@@ -121,6 +121,11 @@ namespace llvm {
       retain();
     }
 
+    IntrusiveRefCntPtr& operator=(const IntrusiveRefCntPtr& S) {
+      replace(S.getPtr());
+      return *this;
+    }
+
     template <class X>
     IntrusiveRefCntPtr& operator=(const IntrusiveRefCntPtr<X>& S) {
       replace(S.getPtr());
@@ -140,7 +145,7 @@ namespace llvm {
 
     T* getPtr() const { return Obj; }
 
-    typedef T * IntrusiveRefCntPtr::*unspecified_bool_type;
+    typedef T* (IntrusiveRefCntPtr::*unspecified_bool_type) () const;
     operator unspecified_bool_type() const {
       return Obj == 0 ? 0 : &IntrusiveRefCntPtr::getPtr;
     }
@@ -150,13 +155,17 @@ namespace llvm {
       other.Obj = Obj;
       Obj = tmp;
     }
+    
+    void resetWithoutRelease() {
+      Obj = 0;
+    }
 
   private:
     void retain() { if (Obj) Obj->Retain(); }
     void release() { if (Obj) Obj->Release(); }
 
     void replace(T* S) {
-      this_type(S).swap(this);
+      this_type(S).swap(*this);
     }
   };
 
@@ -222,4 +231,4 @@ namespace llvm {
 
 } // end namespace llvm
 
-#endif // LLVM_ADT_INTRUSIVE_REF_CNT_PTR
\ No newline at end of file
+#endif // LLVM_ADT_INTRUSIVE_REF_CNT_PTR