|
Boost : |
From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-09 20:42:03
--- David Abrahams <dave_at_[hidden]> wrote:
> "E. Gladyshev" <egladysh_at_[hidden]> writes:
>
> > You are not answering my question. How does the standard defines
> > "reusing storage"?
>
> It does not, just like it doesn't define "allocating storage" or "is"
> or "bulwark". OK, "bulwark" isn't in the standard. If the plain
> English meaning of "reusing storage" isn't enough for you, a comment
> in this example from 3.8/5 should help:
>
> [Example:
> struct B {
> virtual void f();
> void mutate();
> virtual ~B();
> };
> struct D1 : B { void f(); };
> struct D2 : B { void f(); };
> void B::mutate() {
> new (this) D2; // reuses storage -- ends the lifetime of *this
> f(); // undefined behavior
> ... = this; // OK, this points to valid memory
> }
> void g() {
> void* p = malloc(sizeof(D1) + sizeof(D2));
> B* pb = new (p) D1;
> pb->mutate();
> &pb; // OK: pb points to valid memory
> void* q = pb; // OK: pb points to valid memory
> pb->f(); // undefined behavior, lifetime of *pb has ended
> }
This example doesn't prove anything it is just
a one of million possible cases.
In the following code
struct my_type
{
int x;
};
my_type m;
f( (char*)&m.x );
f( char *p )
{
*p = 3;
}
Is the function f() reusing the storage allocated for 'm'
and so ending the lifetime of 'm'?
Independent from your this question,
the bottom line is that if the standard doesn't
define what "reusing storage" is really is,
all the elaborations about object's lifetime
are "bulwark" and nonsense.
Eugene
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk