David Wojtowicz wrote:
>
> I guess my main point was that it is too easy to create code that looks
> perfectly valid (like my example), but had unintended side effects, due to
> the hidden nature of destructors being called as objects go out of scope.
Some of this is a documentation problem. Up to now, we've been
depending on the existence of the examples to cover this. That is, do
things like the examples, and you'll be fine. These issues should be
explicitly covered in the user manual.
> I don't know if the C++ standard prescribes the order in which destructors
> must be called
You can get a PDF copy of the standard for only $18 here:
http://webstore.ansi.org/ No excuses now. :)
> 1) If ResUse::~ResUse() didn't need to call conn_->unlock(), the problem
> would be solved.
I'll be shipping v2.0.7 in the forseeably near future, and it will have
Chris's patch for this in it. I'm not certain that this is a completely
correct fix, but it's certainly part of a correct fix.
> 2) Make the default ctors for ResUse and Result private
Hmmm, maybe. This would have to wait for v3.0.
> 3) Add a note to the docs, warning about deleting Connection before things
> that depend on it go out of scope.
I had in mind a much more extensive discussion. The dependencies are
more complex than that.
> Thanks for listening.
Thanks for complaining constructively. :)