mpa*_*tro 14 c++ cmake clang clang-tidy
我正在为我的项目使用 CMake,我想为项目引入 clang-tidy 检查。
我使用这个目的CMAKE_CXX_CLANG_TIDY
和.clang-tidy
文件检查设置。
我想使用警告作为错误在 CI 中有可靠的方法来检查提交是否引入了一些新的违规行为。不幸的是,由于 3rd 方库,我在启用检查时遇到了一些问题。例如,我使用Eigen
which 是仅标头库。由于这个事实,我在我的代码中收到了一些警告,例如。“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 ) );
Run Code Online (Sandbox Code Playgroud)
我有点不知道如何忽略这类问题,因为header-filter
似乎没有解决这个问题 - 对于其他检查 [bugprone-xxx] 我有类似的问题。除了//NO-LINT
到处添加之外,我还有什么选择?
编辑:为错误添加了一些上下文。
您发布的错误看起来并不虚假。问题可能不在于第三方库,而在于您对它的使用。您没有提供足够的代码来给出完全正确的答案,因为不清楚fDummy
和GetRandom
是什么。如果fDummy
被移入,GetRandom
那么这里就有一个真正的错误。
注释中已经列出了忽略头文件中包含的错误的方法:using -isystem
(在CMake中,导入的目标默认使用此方法,否则您可以手动应用SYSTEM
)target_include_directories
。