让clang-tidy修复头文件 [英] Getting clang-tidy to fix header files

查看:573
本文介绍了让clang-tidy修复头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将当前使用gcc编译的项目移至clang, 并有一堆gcc不会生成的警告(-Winconsistent-missing-override). clang-tidy用于修复*.cpp文件中的这些错误,但是它不涉及hpp文件,因为在数据库中未找到编译命令(正如我期望的那样).

I'm in the process of moving a project currently compiling with gcc to clang, and have a bunch of warnings that gcc didn't generate (-Winconsistent-missing-override). clang-tidy works for fixing these errors in the *.cpp files, however it doesn't touch the hpp files because a compile command wasn't found in the database (as I would expect).

我正在使用ninja生成项目,并使用ninja -t compdb cc cxx > .build/compile_commands.json生成编译数据库.我试过跑步:

I'm using ninja to build the project and ninja -t compdb cc cxx > .build/compile_commands.json to generate the compilation database. I've tried running:

clang-tidy-3.6 -p .build/      \
      $(find src/ -name *.cpp) \
      $(find src/ -name *.hpp) \
      --checks=misc-use-override --fix

修复错误.它拒绝触摸抱怨的头文件:

to fix the errors. It refuses to touch header files complaining:

Skipping .../src/header/file.hpp. Compile command not found.

推荐答案

我通过指定--header-filter=src/选项使它起作用. 有趣的是,修复程序最终被应用了几次,导致输出如下:

I got it working by specifying the --header-filter=src/ option. Interestingly fixes ended up being applied several times causing output like this:

void f() override override override override override;

我通过分别在每个源文件上运行clang-tidy来解决此问题.还要注意,用-p指定的<build-path>还必须包含.clang-format配置,以应用样式.

I worked around this by running clang-tidy on each source file separately. Also note the <build-path> specified with -p must also contain the .clang-format configuration for styling to be applied.

这是我当前的命令迭代:

This is my current iteration of the command:

find src/ -name '*.cpp' -exec \
     clang-tidy-3.6 -p . --header-filter=src/ {}
               --checks=misc-use-override --fix

这篇关于让clang-tidy修复头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆