【发布时间】:2020-07-20 21:16:33
【问题描述】:
我在我的项目中使用 CMake,我想在项目中引入 clang-tidy 检查。
我为此目的使用CMAKE_CXX_CLANG_TIDY 和.clang-tidy 文件进行检查设置。
我想在 CI 中使用 warnings-as-errors 以可靠的方式检查提交是否引入了一些新的违规行为。不幸的是,由于 3rd-party 库,我在启用检查时遇到了一些问题。
例如,我使用Eigen,它是仅标头库。由于这个事实,我在代码中收到了一些警告,例如。 “a_file.cpp”
/snap/cmake/301/bin/cmake -E __run_co_compile --tidy="clang-tidy;--extra-arg-before=--driver-mode=g++" --source=../../a_file.cpp -- /usr/bin/clang++ -DEIGEN_MPL2_ONLY -DEIGEN_STACK_ALLOCATION_LIMIT=16384 -I../../SomePath -I../../SomePath2 -isystem ../../path_to/include/Eigen -m64 -stdlib=libc++ -g -fPIC -std=c++11 -MD -MT a_file.cpp.o -MF a_file.cpp.o.d -o a_file.cpp.o -c a_file.cpp
../../path_to/include/Eigen/Eigen/src/Core/Swap.h:89:36: error: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign,-warnings-as-errors]
a_file.cpp:279:5: note: Loop condition is true. Entering loop body
for( unsigned int i = 0; i < 100; ++i )
^
a_file.cpp:282:13: note: Calling move assignment operator for 'Matrix<float, 3, 1, 0, 3, 1>'
some_name = Vector3f( GetRandom( fDummy ),GetRandom( fDummy ), GetRandom( fDummy ) );
我有点不知道如何忽略此类问题,因为header-filter 似乎无法解决此问题 - 对于其他检查 [bugprone-xxx] 我有类似的问题。除了到处添加//NO-LINT,我还有什么选择?
编辑:为错误添加了一些上下文。
【问题讨论】:
-
为什么 header-filter 或 HeaderFilterRegex 不能解决问题? --header-filter='Eigen/src/Core/.*' 会起作用吗?
-
其实
-header-filter是白名单而不是黑名单。我试过了 - 它不能解决问题。与-isystem类似,这使得 include 被视为系统标头,默认情况下会忽略所有警告(如果没有此选项,我会收到更多警告)。我的理解是这部分代码被内联在a_file.cpp中,并且clang-tidy 将此警告视为.cpp文件本身的问题,而不是.hpp文件的问题。
标签: c++ cmake clang clang-tidy