|
Boost : |
From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-10 15:16:53
--- Douglas Gregor <gregod_at_[hidden]> wrote:
[...]
> ones that prove ways in which the problem can't be solved. You have
> categorically refused to do your share to understand the old arguments, and
> in doing so have closed our minds.
Here is another consideration that shows (I believe)
that your conclusions about undefined behavior and
object lifetime are inconsistent.
struct my_type {...};
/*
5.3.4/8
[...]
[Note: since allocation functions are assumed to return pointers to
storage that is appropriately aligned for objects of any type, this
constraint on array allocation overhead permits the common idiom of
allocating character arrays into which objects of other types will
later be placed. ]
*/
char buf[sizeof(my_type)]; //5.3.4/8 -> can safely allocate my_type in buf
my_type* p1 = new( buf ) my_type;
/*
according to 5.3.4/9
"The address of the created object will not necessarily be the same as that
of the block of storage if the object is an array."
We are not allocating an array, so p == buf
*/
p1->f(); //ok
my_type* p2 = new( buf ) my_type; //reusing *p1 storage
// again p2 == buf
p2->f(); //ok
p1->f(); //undefined -- lifetime of *p1 is ended
Note: p1 is equal p2 and they pointing to the same type,
but p1->f() is undefined while p2->f() is fine.
It is nonsense!
What else can I do to open your minds? :)
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