Examples of errors detected by the V572 diagnostic

V572. It is odd that the object which was created using 'new' operator is immediately cast to another type.


wxWidgets

V572 It is odd that the object which was created using 'new' operator is immediately cast to another type. base appbase.cpp 812


class wxFontMapper : public wxFontMapperBase
{
  ...
}

wxFontMapper *wxConsoleAppTraitsBase::CreateFontMapper()
{
  return (wxFontMapper *)new wxFontMapperBase;
}

Identical errors can be found in some other places:

  • V572 It is odd that the object which was created using 'new' operator is immediately cast to another type. base fmapbase.cpp 428

Cocos2d-x

V572 It is odd that the object which was created using 'new' operator is immediately cast to another type. ccactiontiledgrid.cpp 322


struct Tile
{
  Vec2    position;
  Vec2    startPosition;
  Size    delta;
};

Tile* _tiles;

void ShuffleTiles::startWithTarget(Node *target)
{
  ....
  _tiles = (struct Tile *)new Tile[_tilesCount];  // <=
  Tile *tileArray = (Tile*) _tiles;               // <=
  ....
}

Identical errors can be found in some other places:

  • V572 It is odd that the object which was created using 'new' operator is immediately cast to another type. luabasicconversions.cpp 1301


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;