I have the following test case:
testcase("[room] exits") {
auto [center, east, north, south, west] = make_test_rooms();
check_eq(center->east(), east);
check_eq(center->north(), north);
check_eq(center->south(), south);
check_eq(center->west(), west + 1);
}
When I compile it, clang++ (clang version 5.0.1 (tags/RELEASE_501/final)) reports:
room.cpp:52:7: note: Value stored to '[center, east, north, south, west]' during its initialization is never read
In the code above, testcase
and check_eq
are macros defined for the doctest unit testing package that expand to DOCTEST_TEST_CASE()
(some kind of self-registering variable+function pair) and DOCTEST_CHECK_EQ
(basically, "assert a == b", with magic handling).
I know this code is being executed, since the west + 1
is a deliberately-introduced error. When I run my tests, I get a failure message like this one:
===============================================================================
/.../room.cpp(51)
TEST CASE: [room] exits
/.../room.cpp(57) ERROR!
CHECK_EQ( center->west(), west + 1 )
with expansion:
CHECK_EQ( 0x00007fd6f1d011a0, 0x00007fd6f1d011f8 )
As far as I can see, I am using all of the values in the structured binding: center
appears on the left of my checks, and north, south, east, west
appear on the right. Why is clang++ reporting something as "never read"?
Update
Here is code that reproduces the issue. I run this command line (taken from the output of make VERBOSE=1
and reduced):
$ /opt/local/bin/cmake -E __run_co_compile --tidy=/opt/local/bin/clang-tidy --source=test.cpp -- /opt/local/bin/clang++ -g -std=gnu++1z -o test.cpp.o -c test.cpp
/Users/austin/Code/agb/test.cpp:12:7: warning: Value stored to '[a, b, c]' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
auto [a,b,c] = foo();
^
/Users/austin/Code/agb/test.cpp:12:7: note: Value stored to '[a, b, c]' during its initialization is never read
I used this source file as test.cpp
:
#include <tuple>
static std::tuple<int, int, int>
foo()
{
return {1,2,3};
}
bool
test()
{
auto [a,b,c] = foo();
return a<b and b<c;
}