This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 May 2007 13:46:16 -0000
- Subject: [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/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #85 from rguenth at gcc dot gnu dot org 2007-05-18 14:46 -------
To avoid confusion about what testcase we speak, let's talk about the one
I replicated below. I believe this one is valid as the storage is a union
instantiated in main() and a pointer to it is passed to foo(). It doesn't
matter the argument pointer type is double*, as we access the memory first
as int* (which is ok and starts lifetime of int typed memory) and then we
EOL that object and start lifetime of a long via placement new (alignment
is ok, as is size).
So, anyone disagrees that the below testcase is valid?
inline void* operator new(unsigned long, void* __p) throw() { return __p; }
void __attribute__((noinline)) bar() {};
long __attribute__((noinline)) foo(double *p, int n)
{
long *f;
for (int i=0; i<n; ++i)
{
int *l = (int *)p;
*l = 0;
f = new (p) long;
*f = -1;
}
bar ();
return *f;
}
extern "C" void abort(void);
int main()
{
union {
int i;
long l;
} u;
if (foo((double *)&u, 1) != -1)
abort ();
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286