我正在为我的项目使用 CMake,我想为项目引入 clang-tidy 检查。
我正在为此目的使用 CMAKE_CXX_CLANG_TIDY
和 .clang-tidy
用于检查设置的文件。
我想使用警告作为错误在 CI 中有可靠的方法来检查提交是否引入了一些新的违规行为。不幸的是,由于 3rd 方库,我在启用检查时遇到了一些问题。
例如我使用 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
我还有什么选择到处?编辑:为错误添加了一些上下文。
最佳答案
您发布的错误看起来并不虚假。问题可能不在于第 3 方库,而在于您对它的使用。您没有提供足够的代码来给出完全正确的答案,因为不清楚是什么 fDummy
和 GetRandom
是。如 fDummy
正在搬入 GetRandom
,你这里有一个真正的错误。
注释已经列出了忽略头文件中包含的错误的方法:使用 -isystem
(在 CMake 中,导入的目标默认使用它,否则您可以手动将 SYSTEM
应用到 target_include_directories
)。
关于c++ - clang-tidy - 忽略第三方标题代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61101056/