googletest icon indicating copy to clipboard operation
googletest copied to clipboard

[Bug]: INSTANTIATE_TEST_SUITE_P fails to namespace func param

Open yfeldblum opened this issue 5 months ago • 1 comments
trafficstars

Describe the issue

This example would fail when built with g++ -Werror -Wshadow=compatible-local:

class MyCodeTest : public ::testing::TestWithParam<int> {};
TEST_P(MyCodeTest, Example) {}
INSTANTIATE_TEST_SUITE_P(
    MyCode,
    MyCodeTest,
    ::testing::Values(0),
    [](const ::testing::TestParamInfo<int>& info) {
      return std::to_string(info.param);
    });

Steps to reproduce the problem

https://godbolt.org/z/65oz63933

What version of GoogleTest are you using?

The repro uses gtest-1.10 but the issue remains in gtest-1.17 (latest release as of time of posting) and in main (as of time of posting).

What operating system and version are you using?

Linux.

What compiler and version are you using?

The repro uses gcc-15.1.

What build system are you using?

N/A

Additional context

No response

yfeldblum avatar Jun 13 '25 18:06 yfeldblum

@yfeldblum i sloved this one by doind like this The issue is shadowing of info inside the lambda passed to INSTANTIATE_TEST_SUITE_P. GCC 15+ with -Wshadow=compatible-local warns about shadowing compatible names in lambdas. Solution: Rename the lambda parameter to something unique (like test_info) to avoid name conflicts. we have change this code to [](const ::testing::TestParamInfo& test_info) { return std::to_string(test_info.param); } like this [](const ::testing::TestParamInfo& test_info) { return std::to_string(test_info.param); }

nani12-nithish avatar Jul 03 '25 12:07 nani12-nithish