Handling large volume of boost unit test related warnings with clang-tidy

924 views Asked by At

I'm in the process of setting up a project. I have skeleton tests in place using boost unit-test. Unfortunately a large number of warnings are spawned from the macro expansions. Is there a way to disable these, without have to specify individual line numbers?.

This occurs even when I have a // NOLINT.

An example:

/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 );
2

There are 2 answers

0
Niels Holst On

Try wrapping the offending code thus:

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

// your code here

#pragma clang diagnostic pop
1
TemplateRex On

You probably didn't paste the entire error message, but somewhere in there should be a line that says

warning: disabled expansion of recursive macro [-Wdisabled-macro-expansion]

You can disable this by passing -Wno-disabled-macro-expansion to the clang command line.