...
Code Block | ||||
---|---|---|---|---|
| ||||
class Body; // incomplete class declaration
class Handle {
public:
Handle();
~Handle() { delete impl_; } // deletion of pointer to incomplete class
// ...
private:
Body *impl_;
};
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
class Body {
// ...
};
Handle::~Handle() { delete impl_; } // correct.
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
class Handle {
public:
Handle();
~Handle() {} // correct.
// ...
private:
std::tr1::shared_ptr<Body> impl_;
};
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
class B {
// ...
};
B *getMeSomeSortOfB();
// ...
class D; // incomplete declaration
// ...
B *bp = getMeSomeSortOfB();
D *dp = (D *)bp; // old-stlye cast: legal, but inadvisable
dp = reinterpret_cast<D *>(bp); // new-style cast: legal, but inadvisable
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
class D : public SomeClass, public B {
// ...
};
B *getMeSomeSortOfB() { return new D; }
|
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP39-CPP | medium | unlikely | medium | P4 | L3 |
Automated Detection
Tool | Version | Checker | Description |
---|---|---|---|
Coverity | 6.5 | DELETE_VOID | Fully Implemented |
Bibliography
[Dewhurst 03] Gotcha 39: Casting Incomplete Types
...