我正在将当前使用 gcc 编译的项目移动到 clang,并且有一堆 gcc 未生成的警告( -Winconsistent-missing-override
)。 clang-tidy
用于修复 *.cpp
文件中的这些错误,但它不涉及 hpp
文件,因为在数据库中找不到编译命令正如我所料)。
我正在使用 ninja
来构建项目和 ninja -t compdb cc cxx > .build/compile_commands.json
来生成编译数据库。我试过运行:
clang-tidy-3.6 -p .build/ \
$(find src/ -name *.cpp) \
$(find src/ -name *.hpp) \
--checks=misc-use-override --fix
修复错误。它拒绝触摸头文件抱怨:
Skipping .../src/header/file.hpp. Compile command not found.
原文由 nishantjr 发布,翻译遵循 CC BY-SA 4.0 许可协议
我通过指定
--header-filter=src/
选项让它工作。有趣的是,修复程序最终被应用了多次,导致输出如下:我通过分别在每个源文件上运行
clang-tidy
来解决这个问题。另请注意,用<build-path>
指定的-p
还必须包含.clang-format
配置以应用样式。这是我当前的命令迭代: