[PATCH] [analyzer][Review request] Improved checker lists.
Jordan Rose
jordan_rose at apple.com
Fri May 2 09:46:32 PDT 2014
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
More information about the cfe-commits
mailing list