3

我正在建立一个项目。我使用 boost 单元测试进行了骨架测试。不幸的是,宏扩展会产生大量警告。有没有办法禁用这些,而不必指定单独的行号?

即使我有 // NOLINT,也会发生这种情况。

一个例子:

/home/peter/checkouts/canopen-gateway/./unittests/projs/server/exe/testunit-tcp-socket.cpp:12:1: warning: construction of 'end_suite12_registrar12' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
BOOST_AUTO_TEST_SUITE_END()  // NOLINT
^
/usr/include/boost/test/unit_test_suite.hpp:62:73: note: expanded from macro 'BOOST_AUTO_TEST_SUITE_END'
#define BOOST_AUTO_TEST_SUITE_END()                                     \
                                                                        ^
/usr/include/boost/test/unit_test_suite.hpp:209:62: note: expanded from macro '\BOOST_AUTO_TU_REGISTRAR'
static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), __LINE__ )
                                                             ^
/usr/include/boost/config/suffix.hpp:544:28: note: expanded from macro 'BOOST_JOIN'
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
                           ^
/usr/include/boost/config/suffix.hpp:545:31: note: expanded from macro 'BOOST_DO_JOIN'
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
                              ^
/usr/include/boost/config/suffix.hpp:546:32: note: expanded from macro 'BOOST_DO_JOIN2'
#define BOOST_DO_JOIN2( X, Y ) X##Y
                               ^
note: expanded from here
/usr/include/boost/test/unit_test_suite_impl.hpp:284:17: note: possibly throwing constructor declared here
    explicit    auto_test_unit_registrar( int );
4

2 回答 2

1

尝试包装有问题的代码:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"

// your code here

#pragma clang diagnostic pop
于 2021-09-23T05:56:38.137 回答
1

您可能没有粘贴整个错误消息,但在某处应该有一行说

警告:递归宏的禁用扩展 [-Wdisabled-macro-expansion]

您可以通过传递-Wno-disabled-macro-expansion到 clang 命令行来禁用它。

于 2017-01-28T15:49:10.857 回答