cmake 防止铿锵声整齐地报告升压测试头上的警告

oyt4ldly  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(171)

注2022年12月:看起来这个问题在clang-tidy 14中得到了解决。仅仅通过实验,我就可以用clang-tidy 11, 12 and 13重现这个问题,但用14却不行。
我有一个使用Boost.UnitTest进行测试的Cmake项目。当我用clang-ticky做静态分析时,它报告了一些来自Boost.UnitTest头文件的警告。我想过滤这些警告。
作为示例(忽略细节)

/usr/include/boost/test/tools/old/interface.hpp:84:45: note: expanded from macro 'BOOST_REQUIRE'

# define BOOST_REQUIRE( P )                  BOOST_TEST_TOOL_IMPL( 2, \

                                            ^
/usr/include/boost/test/tools/old/interface.hpp:65:5: note: expanded from macro 'BOOST_TEST_TOOL_IMPL'
    BOOST_TEST_PASSPOINT();                                                     \
    ^
/usr/include/boost/test/unit_test_log.hpp:261:5: note: expanded from macro 'BOOST_TEST_PASSPOINT'
    ::boost::unit_test::unit_test_log.set_checkpoint(           \
    ^
/usr/include/boost/test/unit_test_log.hpp:209:82: note: default parameter was declared here
    void                set_checkpoint( const_string file, std::size_t line_num, const_string msg = const_string() );
                                                                                 ^
/home/user/prj/alf/boost/multi/test/zero_dimensionality.cpp:23:3: error: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls,-warnings-as-errors]
                BOOST_REQUIRE( num_elements(m1) == 3 );

到目前为止,我使用以下代码行添加了对Boost.UnitTest的依赖

target_link_libraries(${TEST_EXE} PRIVATE Boost::unit_test_framework Boost::serialization)

我试着用这个来使Boost.UnitTest成为一个“系统”库,但是我仍然得到同样的警告

target_include_directories(${TEST_EXE} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
    target_link_libraries(${TEST_EXE} PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
    target_link_libraries(${TEST_EXE} PRIVATE ${Boost_SERIALIZATION_LIBRARY})

但结果还是一样。

如何防止clang-tidy检查或报告Boost标头中的错误?

(我接受更改clang-tidy本身配置的答案(我使用了.clang-tidy配置文件);虽然更改CMakeLists.txt似乎更好。)
添加注解:
根据评论中的一个建议,我禁用了这些与Boost. Test“不兼容”的警告。我仍然希望保留它们,并以某种方式将clang-tidy filter作为Boost的头文件。测试:


# -altera-unroll-loops,                                  // BOOST_REQUIRE macro requires this

# -cert-err58-cpp,                                       // BOOST_AUTO_TEST_CASE macro requires this

# -cppcoreguidelines-avoid-non-const-global-variables,   // BOOST_AUTO_TEST_CASE macros require this

# -cppcoreguidelines-macro-usage,                        // BOOST_TEST_MODULE macro requires this

# -cppcoreguidelines-pro-type-vararg,                    // BOOST_REQUIRE macros require this

# -fuchsia-default-arguments-declarations                // BOOST_AUTO_TEST_CASE_TEMPLATE

# -fuchsia-default-arguments-calls,                      // BOOST_REQUIRE macros require this

# -fuchsia-statically-constructed-objects,               // BOOST_AUTO_TEST_CASE creates these

# -hicpp-vararg,                                         // all BOOST_TEST_REQUIRE macros require this
vnjpjtjt

vnjpjtjt1#

好吧,我不完全清楚(对我来说)从这个:
我做CXX=clang++ cmake.. -DCMAKE_CXX_CLANG_TIDY=“clang-tidy”(加上一个用于clang-tidy的配置文件)
clang-tidy是如何或何时被调用的。显然,它使用了一些我不熟悉的CMake魔法。我确实记得有一次看到过这样的东西,但我没有最终使用它是有原因的。
相反,我使用了CMAKE_EXPORT_COMPILE_COMMANDS=On(对于所有基于libclang的工具,以及一些基于libclang的工具,如IDE和LSP服务器,都非常方便)。
根据我的经验,它确实过滤了系统包含,因为它应该(它给出了一个计数的诊断抑制在详细模式)。

qhhrdooz

qhhrdooz2#

如果你使用了库中的宏,而这些宏会引发叮当作响的警告,我不认为现在有什么好的方法可以避免它。即使你将库作为系统库包含(例如,通过-isystem),我的理解是警告仍然会触发,因为宏是在 * 你的代码 * 中使用的,即使它在库中声明。
这里有a proposal来修复它,不幸的是,它似乎自2021年以来一直停滞不前。

相关问题