Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-24 08:49:22

Joaquín Mª López Muñoz <joaquin_at_[hidden]> writes:

> The new rule introduced in Boost.Serialization that forbids saving
> of non-const objects has proved a little controversial. My point of
> view is that the rule, albeit far from perfect, provides some
> level of safety against hard to track errors. Others' opinions differ.
> The current rule is a rough approximation to what IMHO would
> constitute the right enforcement: everytime a trackable object
> is saved, check wether an object with the same address has been
> previously saved and, if so, make sure that the object didn't change.

I don't understand what bugs this is going to catch. Certainly in
this case,

  for( ...
     X x(... );
     ar << x;

the low-level problem isn't that x is changing, but that it's a
different object each time. Two temporally different x's might well
be identical.

But all of this misses the high-level problem: the author of the code
doesn't know what he's doing. You simply can't serialize objects from
distinct scopes with tracking into the same archive, because there may
be aliasing. And there's nothing we can reasonably do to detect that
problem when the aliased objects have the same type (asserting when a
tracked pointer is serialized again with a new type is a great idea).
There should be a mechanism to manually clear all tracking so that the
user can tell the archive that he's serializing tracked objects in a
new scope. Finally, this has nothing at all to do with constness.

Of course, I might be missing something important :)

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at