【问题标题】:cppcheck, how inline-suppression works with misra add-oncppcheck,内联抑制如何与 misra 插件一起使用
【发布时间】:2020-04-23 08:44:05
【问题描述】:

我尝试使用 CppCheck 和 misra 插件进行内联抑制:

我的例子:

    // /* Send number of data */

产生错误:

"misra-c2012-3.1" severity="style" msg="字符序列 /* 和 // 不得在评论中使用"

但如果我尝试过

    // cppcheck-suppress  misra-c2012-3.1
    // /* Send number of data */

我总是有错误。 我尝试了关于 Id 的不同语法:

  • misra-c2012-3.1
  • misra_c2012_3.1
  • misra_3.1
  • misra-3.1

每次都会引发错误。

我使用选项--inline-suppr

【问题讨论】:

  • 为什么一开始就在 cmets 中有 cmets?是 Doxygen 的东西吗?
  • 不,这只是一个测试内联抑制的示例,打破 MISRA 规则的简单方法。

标签: cppcheck misra


【解决方案1】:

您似乎发现了一个错误。 你的方法在我看来是正确的。

对于以下 C 代码(在文件 misra_suppression_test.c 中),抑制有效:

// cppcheck-suppress misra-c2012-2.7
void misra_2_7_unused_param (int *param1, int unused_param)
{
    *param1 = 42U;
}

如果没有--inline-suppr,则报告违规:

$ ./cppcheck --enable=style --addon=misra misra_suppression_test.c
Checking misra_suppression_test.c ...
misra_suppression_test.c:2:6: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.7]
void misra_2_7_unused_param (int *param1, int unused_param)
     ^

--inline-suppr 不再报告违规行为:

$ ./cppcheck --enable=style --addon=misra --inline-suppr misra_suprpession_test.c
Checking misra_suppression_test.c ...

看起来抑制不适用于规则 3.1 左右。

【讨论】:

  • 我做了和你一样的测试。违规行为未报告。所以是的,显然这是一个错误。有些规则有效,有些则无效……我会报告的。谢谢:)
猜你喜欢
  • 2016-10-08
  • 2017-04-25
  • 1970-01-01
  • 2011-02-26
  • 2020-05-16
  • 2017-01-29
  • 2014-05-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多