【发布时间】:2015-02-16 02:20:34
【问题描述】:
我有一个驱动 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.
我无法找出抑制这两者的语法,而且手册也无济于事。单独的行、空格、逗号、冒号和分号都失败。单独的行给我“抑制不匹配”,其余的只是无效:
//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 中点击“刷新”并不会刷新所有内容,我必须重新加载 cppcheck 文件以获取要更新的抑制更改。即工具栏上的“打开文件”图标,而不是右手边的“刷新”图标。
事实证明,空格分隔有效:
//cppcheck-suppress variableScope unreadVariable
【问题讨论】:
标签: cppcheck