抑制一行中的多个警告?

Cod*_*tor 5 cppcheck

我有一个驱动 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);
Run Code Online (Sandbox Code Playgroud)

Cppcheck 说:

The scope of the variable 'afterDb' can be reduced.
Variable 'afterDb' is assigned a value that is never used.
Run Code Online (Sandbox Code Playgroud)

我无法找出抑制这两者的语法,并且手册没有帮助。分隔线、空格、逗号、冒号和分号都失败。单独的行给我“抑制不匹配”,其余的都是无效的:

    //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"
Run Code Online (Sandbox Code Playgroud)

cppcheck 是否允许我内联执行此操作,还是必须在命令行上使用 XML 执行此操作?


cppcheck-gui 工具栏

抱歉,事实证明存在一个令人困惑的问题:在 cppcheck-gui 中点击“刷新”并不会刷新所有内容,我必须重新加载 cppcheck 文件才能获取要更新的抑制中的更改。也就是说,工具栏上的“打开文件”图标而不是右手边的“刷新”图标。

事实证明,空间分隔有效:

//cppcheck-suppress variableScope unreadVariable
Run Code Online (Sandbox Code Playgroud)

pix*_*ase 3

要在同一行上使用多个抑制,请使用逗号分隔的列表。

手册中:

arr[10] = arr[10] / 0; // cppcheck-suppress[arrayIndexOutOfBounds,zerodiv]
Run Code Online (Sandbox Code Playgroud)

您还可以堆叠抑制:

// cppcheck-suppress arrayIndexOutOfBounds
// cppcheck-suppress zerodiv
arr[10] = arr[10] / 0;
Run Code Online (Sandbox Code Playgroud)