Menu

spurious warnings about BOOST_AUTO_TEST_CASE_run

2026-04-06
2026-04-07
  • Stevan White

    Stevan White - 2026-04-06

    test_a.cpp -- triggers warning:

    #define BOOST_AUTO_TEST_CASE(...) void BOOST_AUTO_TEST_CASE_run(__VA_ARGS__)
    
    int x = 1;  // file-scope declaration before first test case
    
    BOOST_AUTO_TEST_CASE( test_one )
    {
        x = 2;
    }
    

    test_b.cpp -- no warning:

    #define BOOST_AUTO_TEST_CASE(...) void BOOST_AUTO_TEST_CASE_run(__VA_ARGS__)
    
    BOOST_AUTO_TEST_CASE( test_one )
    {
        int x = 1;
    }
    

    Command:

    cppcheck --std=c++17 --enable=unusedFunction test_a.cpp test_b.cpp
    

    Expected: consistent behaviour -- either both warned or neither.

    Observed: only test_a.cpp triggers [unusedFunction] for
    BOOST_AUTO_TEST_CASE_run.

    Root cause: the boost.cfg expansion
    void BOOST_AUTO_TEST_CASE_run(__VA_ARGS__) collapses
    all test cases to the same function name.
    The inconsistency between files appears to depend on whether file-scope
    declarations precede the first macro invocation.

     
  • CHR

    CHR - 2026-04-07

    cppcheck will warn on the first definition of a function, so the warning will change if the order of the files on the command line is flipped.
    The configuration of BOOST_AUTO_TEST_CASE in boost.cfg will need to be fixed though.
    https://trac.cppcheck.net/ticket/14654

     

    Last edit: CHR 2026-04-07

Log in to post a comment.

MongoDB Logo MongoDB