2016-12-09 60 views
3

我發現--suppress=unmatchedSuppression只能抑制cppcheck選項中不匹配的抑制類型,但不能抑制不匹配的內聯抑制。cppcheck如何抑制內聯不匹配的抑制?

這是預期的行爲?

test.c的

  • 4號線是錯誤的。它應該被警告arrayIndexOutOfBounds

  • 7號線沒問題。它不應該被警告arrayIndexOutOfBounds

我有兩條線路在線cppcheck-suppress

1 void f() { 
    2  char arr[5]; 
    3  // cppcheck-suppress arrayIndexOutOfBounds 
    4  arr[10] = 0; 
    5 
    6  // cppcheck-suppress arrayIndexOutOfBounds 
    7  const char ok[] = "this line is ok"; 
    8 } 

情況1

禁止cstyleCast,它不在代碼存在。

cppcheck --inline-suppr --force --enable=all 
      --xml-version=2 --suppress=cstyleCast test.c 
      2>cppcheckresults.xml 

我得到

  1. unmatchedSuppression: arrayIndexOutOfBounds在警告(以及其他不相關的警告)test.cline 7(預期)

  2. unmatchedSuppression: cstyleCast*line 0(預期)

情況2

同情況1,但額外--suppress=unmatchedSuppression選項

cppcheck --inline-suppr --force --enable=all 
      --xml-version=2 --suppress=cstyleCast --suppress=unmatchedSuppressiontest.c 
      2>cppcheckresults.xml 

我想到以前都警告unmatchedSuppression走開。但我仍然得到

  1. unmatchedSuppressiontest.cline 7(預計不會)

回答

1

我最近發現的是,從內聯鎮壓的unmatchedSuppression警告不能由通用--suppress=unmatchedSuppression被抑制或將只是警告ID在--suppressions-list文件中。你必須用文件名來限定它。例如--suppress=unmatchedSuppression:test.c