Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langcpp

class Body; // incomplete class declaration

class Handle {
  public:
    Handle();
    ~Handle() { delete impl_; } // deletion of pointer to incomplete class
    // ...
  private:
    Body *impl_;
};

...

Code Block
bgColor#ccccff
langcpp

class Body {
    // ...
};

Handle::~Handle() { delete impl_; } // correct.

...

Code Block
bgColor#ccccff
langcpp

class Handle {
  public:
    Handle();
    ~Handle() {} // correct.
    // ...
  private:
    std::tr1::shared_ptr<Body> impl_;
};

...

Code Block
bgColor#FFcccc
langcpp

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
bgColor#FFcccc
langcpp

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

Coverity6.5DELETE_VOIDFully Implemented

Bibliography

[Dewhurst 03] Gotcha 39: Casting Incomplete Types

...