------- Comment #3 from rguenth at gcc dot gnu dot org 2010-09-21 10:12 -------
The following is miscompiled since ever (and also ICC miscompiles it), so
I'm not sure if it is valid to use 'f' to refer to the Bar object.
namespace std {
typedef __SIZE_TYPE__ size_t;
}
inline void* operator new(std::size_t, void* __p) throw() {
return __p;
}
extern "C" void abort (void);
class Foo {
public:
virtual void test (void) { abort (); }
};
class Bar : public Foo {
public:
virtual void test (void) { }
};
int main()
{
Foo f;
new (&f) Bar();
f.test();
return 0;
}
A variant with using a pointer of type Bar * like
int main()
{
Foo f;
static_cast<Foo *>(new (&f) Bar())->test();
return 0;
}
only breaks on recent trunk.
int main()
{
Foo f;
new (&f) Bar();
(&f)->test();
return 0;
}
also breaks always. While
int main()
{
Foo f, *p;
p = new (&f) Bar();
p->test();
return 0;
}
works.
int main()
{
Foo f, *p;
new (&f) Bar();
((Foo *)(void *)&f)->test();
return 0;
}
also works.
Fun.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45734