------- 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