Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-09 20:53:33


--- 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
> }
> ---end example]

Sorry let me fix my last message. I was interrupted.

This example doesn't prove anything it is just
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 answer to this question,
the bottom line is that if the standard doesn't
define what "reusing storage" really is,
all the elaborations about object's lifetime
are "bulwark" and nonsense.
The plain English has nothing do with it.

If we are so paranoid about the standard
we should not be happy with the fact that
the standard doesn't define the most basic
concepts.

The stack solution for variant doesn't have
any problem for practicle stand point.
The only problem is the standard but
the standard doesn't have a standard
for this case.

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