Repository navigation
Conversation
…on and shadow warnings
When SCOPED_TRACE is invoked multiple times on the same line (e.g. inside macro expansions or compact test assertions), concatenating __LINE__ resulted in duplicate variable names ('gtest_trace_<line>'), leading to compiler errors or -Wshadow warnings.
Introduce GTEST_UNIQUE_IDENTIFIER_ in gtest-internal.h using __COUNTER__ when available (falling back to __LINE__), ensuring distinct dummy variable names across multiple invocations on the same line and across nested scopes.
Closes google#5143
Signed-off-by: Aryan Sachin <aryansachinixd@gmail.com>
Aryan9891
added a commit
to Aryan9891/Aryan9891
that referenced
this pull request
Nov 2, 2026
Signed-off-by: Aryan Sachin <aryansachinixd@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
SCOPED_TRACEis invoked multiple times on the same line (e.g. inside macro expansions, multiple assertions in one macro, or compact test assertions), concatenating__LINE__results in identical variable names (gtest_trace_<line>), producing compiler errors (redefinition of 'gtest_trace_<line>') or-Wshadowwarnings under-Werror.This PR introduces
GTEST_UNIQUE_IDENTIFIER_ingtest-internal.hutilizing__COUNTER__when supported across GCC, Clang, and MSVC (with fallback to__LINE__), ensuring distinct variable names across multiple invocations on the same line and across nested scopes.Changes
googletest/include/gtest/internal/gtest-internal.h: IntroduceGTEST_UNIQUE_IDENTIFIER_(name)using__COUNTER__where available.googletest/include/gtest/gtest.h: UpdateSCOPED_TRACEto declare itsScopedTracedummy variable usingGTEST_UNIQUE_IDENTIFIER_(gtest_trace_).googletest/test/gtest_unittest.cc: Add regression testScopedTraceTest.CompilesMultipleTracesOnSameLineasserting twoSCOPED_TRACEinvocations compile cleanly on the same line.Closes #5143