c++ - 使用配置文件禁用或启用 cppcheck 警告
问题描述
使用 clang-tidy 静态分析器,我可以在项目的根目录中保留一个文件 ( .clang-tidy
),其中包含我想要激活或停用的警告。
clang-tidy
将寻找这个文件(据我所知)并使用那里定义的选项。这使我免于在 CMake 或 Makefiles 中对长命令行进行硬编码。
cppcheck
静态分析器可以做同样的事情吗?
目前我有这个很长的命令行硬编码:
cppcheck --max-ctu-depth=3 --enable=all --inline-suppr --suppress=*:*thrust/complex* --suppress=missingInclude --suppress=syntaxError --suppress=unmatchedSuppression --suppress=preprocessorErrorDirective --language=c++ --std=c++14 --error-exitcode=666
.clang-tidy
这是我保留在项目根目录的配置文件示例:
---
Checks: '
*,
-readability-magic-numbers,
-modernize-use-nodiscard,
-altera-struct-pack-align,
-cert-err58-cpp,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-avoid-magic-numbers,
-fuchsia-default-arguments-calls,
-fuchsia-trailing-return,
-fuchsia-statically-constructed-objects,
-fuchsia-overloaded-operator,
-hicpp-vararg,
-hicpp-no-array-decay,
-llvm-header-guard,
-llvmlibc-restrict-system-libc-headers,
-llvmlibc-implementation-in-namespace,
-llvmlibc-callee-namespace
'
WarningsAsErrors: '*'
HeaderFilterRegex: '.'
AnalyzeTemporaryDtors: false
FormatStyle: file
...
解决方案
You can store the configuration in a *.cppcheck
file and then use the --project
command line option to run the check. See the manual - Cppcheck GUI project section.
cppcheck
files are normally generated by CppCheckGUI via File -> New project file. The exact syntax is undocumented but it's basically just an XML file and looks to be fairly straightforward if you want to create the file directly without using the GUI.
Sample test.cppcheck
file:
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>test2-cppcheck-build-dir</builddir>
<platform>Unspecified</platform>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>false</check-unused-templates>
<max-ctu-depth>10</max-ctu-depth>
<exclude>
<path name="WINDOWS/"/>
</exclude>
<suppressions>
<suppression>IOWithoutPositioning</suppression>
</suppressions>
</project>
推荐阅读
- assembly - 访问 PIT (?) IO 端口 44h 和 46h - 这些端口有什么作用?
- python - python dirsync (rsync) 对子文件夹不起作用
- javascript - Discord Bot 没有响应
- node.js - 从处理中执行的 bash 脚本中执行 nodejs
- visual-studio-code - VSCODE:SFTP 连接“未找到配置。(文件:///...”
- sql-server - 使用快照隔离防止 SQL 视图被冗长的删除/插入事务阻塞
- postgresql - 基于辅助表行 PGSQL 动态创建和填充列
- .net - 我有最新的 .NET 框架,但显示 ERROR .NET V 4.0.30319
- kotlin - 获取滑动时Viewholder(RecyclerView)移动了多少像素
- java - 在具有不同列的两个不同数据库上映射实体