小さい頃はエラ呼吸

いつのまにやら肺で呼吸をしています。


【cppcheck】warning: Redundant assignment of 'xxx' to itself.

はじめに

C++の静的解析ツール「cppcheck」でソースコードを静的解析した場合に、以下の警告がでることがあります。

warning: Redundant assignment of 'xxx' to itself.

cppcheckのバージョン
  • v1.67
サンプルプログラム

以下のソースプログラムを解析にかけると表示されます。

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{

  int hoge = 0;
  hoge = hoge;  // warning: Redundant assignment of 'hoge' to itself.

  printf("%d\n", hoge);

  _getch();
  return 0;
}

上記のように、左辺と右辺が同じ値の場合に警告が表示されます。

関連記事