3

我正在使用 C++ 的 static_assert 功能在编译时检查通常应该通过的东西,例如:

static_assert( SOME_CONSTANT < 1000u, "..." );

在该代码上运行 PC-lint(版本 9.00k)会发出注释 948:“运算符 '<' 始终计算为 True”,这对于 static_asserts 来说毫无意义。

我知道我可以将 a 添加//lint !e948到每个 static_assert (这是我现在所做的)或全局禁用 948,但这也会在其他任何地方隐藏合法错误。

是否可以告诉 PC-lint 不评估/检查 static_asserts 中的表达式?

4

2 回答 2

0

您可以教 PC-Lint 以与处理 assert() 相同的方式处理 static_assert()。只需将以下行添加到您的代码中:

#ifdef _lint
//lint -function(__assert, static_assert)
void static_assert(bool, const char*);
#endif
于 2015-03-07T21:24:58.050 回答
0

我将以下行添加到我的 .lnt 配置文件中以解决此问题。

-dstatic_assert()= // ignore keyword static_assert and following parenthetical

于 2018-12-05T15:10:01.407 回答