Leo*_*nid 1 cppcheck visual-studio-code vscode-tasks
我正在为 vscode 设置一个“cppcheck”任务。它有效,但问题匹配器无法捕获问题。
我尝试过“$gcc”问题匹配器以及一些自定义配置。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cppcheck",
"type": "shell",
"command": "cppcheck --template=gcc --enable=style --project=${workspaceFolder}/build/compile_commands.json",
"problemMatcher": "$gcc",
}
]
}
Run Code Online (Sandbox Code Playgroud)
或这个:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cppcheck",
"type": "shell",
"command": "cppcheck --template=gcc --enable=warning src/jc_certreq.cpp",
"problemMatcher": {
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
例如终端显示这样的错误:
/home/user/workspace/project/myprogram.c:440: error: Memory leak: exts
Run Code Online (Sandbox Code Playgroud)
但它不会出现在“问题”栏中。
我自己正在寻找解决方案,但只能找到这个悬而未决的问题。所以我继续修改它并最终让它工作。
问题似乎是旧版本的 Cppcheck(我使用的是 1.82 版)尚不支持打印列。看起来直到 Cppcheck 1.84 才添加支持。但是,默认$gcc问题匹配器期望列号存在。
这是使用 gcc 模板时 Cppcheck 1.82 打印的消息示例:
utilities/thread/condition.h:12: warning: The class 'Condition' has 'copy constructor' but lack of 'operator='.
Run Code Online (Sandbox Code Playgroud)
虽然 GCC 6.3 打印的错误如下所示:
dump_tool.c:40:36: fatal error: generated/autoconf.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
除了缺少列号之外,它们几乎相同。简单地从模式中删除它就解决了我的问题。问题匹配并显示在问题选项卡中。
除此之外,我调整了我的severitytowarning以便这些也出现在问题选项卡中,并且我在使用相对路径时将fileLocationto更改relative为。
这是我用于我的项目的完整任务定义:
utilities/thread/condition.h:12: warning: The class 'Condition' has 'copy constructor' but lack of 'operator='.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1107 次 |
| 最近记录: |