Versions Compared

Key

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

The use of incomplete class declarations (also known as "forward" declarations) is common. While it is possible to declare pointers and references to incomplete classes, because the class definition is not available it 's is not possible to access a member of the class, determine the size of the class object, and so on. However, it is possible to cast and delete a pointer to an incomplete class, but this is never a good idea.

...

In the case of an old-style cast, the address adjustment will, however, take place if the cast is performed at a point where the structure of the class D is known. This different, context-dependent behavior of the old-style cast can result in very challenging bugs.

Compliant Solution

...

Avoid casting to or from pointers to incomplete classes. If such a cast is, for some reason, absolutely necessary, prefer reinterpret_cast to an old-style cast because it will exhibit the same behavior whether or not the class is incomplete.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

ERR01 EXP36-A C

2 (medium)

1 (unlikely)

2 (medium)

P4

L3

...