从一行中抑制多个警告?
Suppress multiple warnings from one line?
我有一个驱动 cppcheck 的代码片段,因为它看不到日志调用中使用的变量。所以我得到未使用的变量和范围缩小警告:
double start = GetTimeOfDayDoubleSec(), afterDb = 0;
if (LoadFromDatabase(serials)) {
afterDb = GetTimeOfDayDoubleSec();
Cache.ResetDebugFlags(serials);
}
double end = GetTimeOfDayDoubleSec();
ZLOG_INFO("DB time %f, total %f", afterDb ? afterDb - start : 0, end - start);
Cppcheck 说:
The scope of the variable 'afterDb' can be reduced.
Variable 'afterDb' is assigned a value that is never used.
我无法找出抑制这两者的语法,手册也没有帮助。单独的行,spaces,逗号,冒号和分号都失败了。单独的行给我 "suppression not matched",其余的都是无效的:
//cppcheck-suppress variableScope
//cppcheck-suppress unreadVariable
//cppcheck-suppress variableScope unreadVariable
//cppcheck-suppress variableScope,unreadVariable
//cppcheck-suppress variableScope;unreadVariable
double afterDb = 0;
Failed to add suppression. Invalid id "variableScope:unreadVariable"
cppcheck 是否允许我在线执行此操作,还是我必须在命令行上使用 XML 来执行此操作?
抱歉,事实证明有一个令人困惑的问题:在 cppcheck-gui 中点击 "refresh" 并没有刷新所有内容,我必须重新加载 cppcheck 文件以获取抑制中的更改以更新。即,工具栏上的 "open file" 图标而不是右手 "refresh" 图标。
原来space分开的作品:
//cppcheck-suppress variableScope unreadVariable
首先...当我阅读您的代码时,在我看来 Cppcheck 编写了 FP。我们不应该警告该代码,不是吗?我希望 FP 是固定的。我复制并粘贴了您的代码,但未能为其重现 FP - 因此您的真实代码中可能存在某些混淆 Cppcheck 的内容。
内联抑制的代码在 cppcheck 预处理器中(在 lib/preprocessor.cpp 文件中搜索 "cppcheck-suppress")。据我所知,您目前不能使用多个内联抑制。
如果您有时间并想帮助我们,请随时:
- 在我们的 trac 中创建一个票证 http://trac.cppcheck.net 并附上修复此问题的补丁。
- 或者,在 github 存储库 http://github.com/danmar/cppcheck 中创建一个拉取请求来解决这个问题。
我会说 space 分隔的内联抑制会很好。
Does cppcheck let me do this inline, or do I have to do it using XML on the command line?
也许这就是你的意思..但你可以使用 --suppress 或 --suppressions-list。
要在同一行上使用多个抑制,请使用逗号分隔列表。
来自manual:
arr[10] = arr[10] / 0; // cppcheck-suppress[arrayIndexOutOfBounds,zerodiv]
你也可以叠加压制:
// cppcheck-suppress arrayIndexOutOfBounds
// cppcheck-suppress zerodiv
arr[10] = arr[10] / 0;
我有一个驱动 cppcheck 的代码片段,因为它看不到日志调用中使用的变量。所以我得到未使用的变量和范围缩小警告:
double start = GetTimeOfDayDoubleSec(), afterDb = 0;
if (LoadFromDatabase(serials)) {
afterDb = GetTimeOfDayDoubleSec();
Cache.ResetDebugFlags(serials);
}
double end = GetTimeOfDayDoubleSec();
ZLOG_INFO("DB time %f, total %f", afterDb ? afterDb - start : 0, end - start);
Cppcheck 说:
The scope of the variable 'afterDb' can be reduced.
Variable 'afterDb' is assigned a value that is never used.
我无法找出抑制这两者的语法,手册也没有帮助。单独的行,spaces,逗号,冒号和分号都失败了。单独的行给我 "suppression not matched",其余的都是无效的:
//cppcheck-suppress variableScope
//cppcheck-suppress unreadVariable
//cppcheck-suppress variableScope unreadVariable
//cppcheck-suppress variableScope,unreadVariable
//cppcheck-suppress variableScope;unreadVariable
double afterDb = 0;
Failed to add suppression. Invalid id "variableScope:unreadVariable"
cppcheck 是否允许我在线执行此操作,还是我必须在命令行上使用 XML 来执行此操作?
抱歉,事实证明有一个令人困惑的问题:在 cppcheck-gui 中点击 "refresh" 并没有刷新所有内容,我必须重新加载 cppcheck 文件以获取抑制中的更改以更新。即,工具栏上的 "open file" 图标而不是右手 "refresh" 图标。
原来space分开的作品:
//cppcheck-suppress variableScope unreadVariable
首先...当我阅读您的代码时,在我看来 Cppcheck 编写了 FP。我们不应该警告该代码,不是吗?我希望 FP 是固定的。我复制并粘贴了您的代码,但未能为其重现 FP - 因此您的真实代码中可能存在某些混淆 Cppcheck 的内容。
内联抑制的代码在 cppcheck 预处理器中(在 lib/preprocessor.cpp 文件中搜索 "cppcheck-suppress")。据我所知,您目前不能使用多个内联抑制。
如果您有时间并想帮助我们,请随时:
- 在我们的 trac 中创建一个票证 http://trac.cppcheck.net 并附上修复此问题的补丁。
- 或者,在 github 存储库 http://github.com/danmar/cppcheck 中创建一个拉取请求来解决这个问题。
我会说 space 分隔的内联抑制会很好。
Does cppcheck let me do this inline, or do I have to do it using XML on the command line?
也许这就是你的意思..但你可以使用 --suppress 或 --suppressions-list。
要在同一行上使用多个抑制,请使用逗号分隔列表。
来自manual:
arr[10] = arr[10] / 0; // cppcheck-suppress[arrayIndexOutOfBounds,zerodiv]
你也可以叠加压制:
// cppcheck-suppress arrayIndexOutOfBounds
// cppcheck-suppress zerodiv
arr[10] = arr[10] / 0;