Okay, let's look at this example:
class A {
public:
virtual void f();
};
class B : public A {
public:
void f();
};
void test() {
A *a = new A;
new(a) B;
a->f(); // warn
}
Both `A` and `B` have `f()` methods, so it's okay to invoke `f()` on an
instance of type `B` (whether through an `A*` or a `B*`). //This// code is
perfectly acceptable:
void test() {
A *a = new A;
a->~A();
static_assert(sizeof(A) == sizeof(B) && alignof(A) == alignof(B),
"different allocation requirements");
new(a) B;
a->f(); // okay, calls B::f.
}
In fact, this would be okay even if `A::f` weren't virtual.
I think the interesting thing to check is whether you are reinitializing an
object whose destructor hasn't been called, and if there are any references to
sub-objects used after the destructor has been called. Simply accessed members
of the new object through the existing pointer is not an error.
http://reviews.llvm.org/D3457
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits