Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2006-03-05 20:19:41


Consider this constructor from the intrusive_ptr doc
(http://boost.org/libs/smart_ptr/intrusive_ptr.html):

   intrusive_ptr(T * p, bool add_ref = true);

   Effects: if(p != 0 && add_ref) intrusive_ptr_add_ref(p);.

Note in particular that nothing is said about exceptions being thrown.
Presumably intrusive_ptr_add_ref may throw, as I can't find any restriction
to the contrary.

Now consider these constructors from the same document:

   intrusive_ptr(intrusive_ptr const & r); // never throws
   template<class Y> intrusive_ptr(intrusive_ptr<Y> const & r); // never throws

   Effects: if(r.get() != 0) intrusive_ptr_add_ref(r.get());.

They are documented not to throw, yet both call intrusive_ptr_add_ref. How
can it be that the top constructor above may throw, but these constructors
may not?

FWIW, it seems to me that all three should be allowed to throw, unless some
constraint is imposed on the implementation of intrusive_ptr_add_ref. For
example, perhaps intrusive_ptr_add_ref wants to throw if its reference
count will overflow -- maybe because it's using only an 8-bit counter.
Isn't that possible?

Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net