Stevan White - 18 hours ago

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.