Skip to content

Conversation

@gaspardpetit
Copy link
Contributor

Fix "unused variable" warning when GTEST_HAS_STREAM_REDIRECTION is set to false in gtest-port.cc

The three guarded constants are used only when GTEST_HAS_STREAM_REDIRECTION is enabled and currently trigger the following warnings when GTEST_HAS_STREAM_REDIRECTION is disabled:

1\googletest\googletest\src\gtest-port.cc(99,11): warning : unused variable 'kStdOutFileno' [-Wunused-const-variable]
1>const int kStdOutFileno = STDOUT_FILENO;
1>          ^
1>\googletest\googletest\src\gtest-port.cc(100,11): warning : unused variable 'kStdErrFileno' [-Wunused-const-variable]
1>const int kStdErrFileno = STDERR_FILENO;

Fix "unused variable" warning when GTEST_HAS_STREAM_REDIRECTION is set to false in gtest-port.cc
@gaspardpetit gaspardpetit changed the title Fix "unused variable" warning Fix "unused variable" warning when GTEST_HAS_STREAM_REDIRECTION is set to false in gtest-port.cc May 30, 2022
@derekmauro derekmauro self-assigned this Jun 6, 2022
namespace testing {
namespace internal {

#if GTEST_HAS_STREAM_REDIRECTION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of placing the guards here, can these variables simply be moved closer to where they are used, near CaptureStdout()/CaptureStderr(), where they would already be inside the GTEST_HAS_STREAM_REDIRECTION block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

Move declaration of kStdOutFileNo and kStdErrFileno closer to where they are used to avoid having to guard for GTEST_HAS_STREAM_REDIRECTION twice
@copybara-service copybara-service bot merged commit 191ca1f into google:main Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants