unused-variable warnings with value-parameterized tests from gmock 1.7.0 with gcc 5

416 views
Skip to first unread message

Mark Abraham

unread,
May 7, 2015, 1:21:21 PM5/7/15
to googletes...@googlegroups.com
Hi,

Compiling value-parameterized tests from gmock 1.7.0 with gcc 5 issues warnings about the way int variables are created but not used, e.g.

../src/external/gmock-1.7.0/gtest/include/gtest/gtest-param-test.h:1409:7: warning: ‘{anonymous}::gtest_NoFatalErrorWhenWritingFromGmxTraj_dummy_’ defined but not used [-Wunused-variable]
   int gtest_##prefix##test_case_name##_dummy_ = \
       ^
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:154:1: note: in expansion of macro ‘INSTANTIATE_TEST_CASE_P’
 INSTANTIATE_TEST_CASE_P(NoFatalErrorWhenWritingFrom,
 ^
../src/external/gmock-1.7.0/gtest/include/gtest/gtest-param-test.h:1409:7: warning: ‘{anonymous}::gtest_NoFatalErrorWhenWritingFromTrjconvWithIndexGroupSubset_dummy_’ defined but not used [-Wunused-variable]
   int gtest_##prefix##test_case_name##_dummy_ = \
       ^
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:158:1: note: in expansion of macro ‘INSTANTIATE_TEST_CASE_P’
 INSTANTIATE_TEST_CASE_P(NoFatalErrorWhenWritingFrom,
 ^
In file included from ../src/external/gmock-1.7.0/gtest/include/gtest/gtest.h:58:0,
                 from ../src/testutils/integrationtests.h:46,
                 from ../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:43:
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:87:8: warning: ‘{anonymous}::GmxTraj_WithDifferentInputFormats_Test::gtest_registering_dummy_’ defined but not used [-Wunused-variable]
 TEST_P(GmxTraj, WithDifferentInputFormats)
        ^
../src/external/gmock-1.7.0/gtest/include/gtest/internal/gtest-internal.h:1133:3: note: in definition of macro ‘GTEST_TEST_CLASS_NAME_’
   test_case_name##_##test_name##_Test
   ^
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:87:1: note: in expansion of macro ‘TEST_P’
 TEST_P(GmxTraj, WithDifferentInputFormats)
 ^
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:128:8: warning: ‘{anonymous}::TrjconvWithIndexGroupSubset_WithDifferentInputFormats_Test::gtest_registering_dummy_’ defined but not used [-Wunused-variable]
 TEST_P(TrjconvWithIndexGroupSubset, WithDifferentInputFormats)
        ^
../src/external/gmock-1.7.0/gtest/include/gtest/internal/gtest-internal.h:1133:3: note: in definition of macro ‘GTEST_TEST_CLASS_NAME_’
   test_case_name##_##test_name##_Test
   ^
../src/gromacs/gmxana/legacytests/gmx_traj_tests.cpp:128:1: note: in expansion of macro ‘TEST_P’
 TEST_P(TrjconvWithIndexGroupSubset, WithDifferentInputFormats)
 ^


Presumably these int variables exist to get test-registration code executed early on. Can we consider using __attribute__((unused)) for these, please?

Mark

David Hallas

unread,
May 8, 2015, 11:05:38 AM5/8/15
to googletes...@googlegroups.com
Hi Mark,

I have run into the exact same problem. I have attached a reduced test case that shows the problem, when compiling with:

g++-5.1.0 -std=c++11 -Wall -O2 c -o test.o test.cpp

I see the same problem. The problem seems to disappear if the test case is not in an unnamed namespace, it also disappears when removing -Wall or -O2. I have also attached a simple patch that fixes the problem. Is it possible to get this submitted upstream?

Thanks

/David
test.cpp
gtest-1.7.0_gcc_5_1_compilation_fix.patch

Samuel Benzaquen

unread,
May 8, 2015, 11:07:32 AM5/8/15
to Mark Abraham, Google C++ Testing Framework
Thanks for the report.
I submitted a fix yesterday and will go out to trunk soon.
_San
 

Mark

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Abraham

unread,
May 8, 2015, 11:25:07 AM5/8/15
to googletes...@googlegroups.com, mark.j....@gmail.com
Hi,
Great, thanks. Let me know if any testing would help.

Mark

 
 

Mark

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages