This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: gcc-bugzilla at gcc dot gnu dot org
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: 18 May 2007 16:13:05 -0500
- Subject: Re: [Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- References: <bug-29286-10053@http.gcc.gnu.org/bugzilla/> <20070518173835.4951.qmail@sourceware.org>
"ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> writes:
| But I don't think that is the question at hand. The variable is always being
| accessed in the same type, which is also the type of its declaration. The
| question at hand is this:
|
| void f(double* p) { *(int*)p = 3; long *l = new (p) long; *l = 4; }
| void g() { int i; f((double *)&i); }
|
| And the specific question is whether we are permitted to interchange the
| assignments to *p and *l.
After the placement new, the lifetime of *p is ended, and the lifetime
of *l starts there. I don't think that leaves room for exchanging the
stores to *p and *l.
| Let's consider this:
|
| void f(double* p) { *(int*)p = 3; long *l = (long*)p; *l = 4; }
|
| Is that valid?
If p is pointing to a union object that contain both int and long,
yes, it is valid. Otherwisem, it is not.
| Is the compiler permitted to interchange the assignments to *p
| and *l?
It is valid if we have a union object, otherwise, no.
-- Gaby