You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using relatively new GCC (14.2.0) with globally enabled both high optimization (-O3) and nullptr dereference warnings (-Wnull-dereference), the compiler issues multiple null dereferece warnings from within gtest target.
Indeed, GetTestInfo , GetTestSuite, GetMutableSuiteCase have a nullptr return path.
I don't believe that there is a way to make them return a nullptr with typical usage, however the compiler can't see through this and issues a warning.
Proposed solution
Add index assertions in GetTestInfo , GetTestSuite, GetMutableSuiteCase as presented in add_assertions.patch
(Please note that the patch changes the indice used in GetTestSuite to be more consistent with the use in GetTestSuite and GetMutableSuiteCase. The other reason is to avoid unused variable warning, when index < 0 check is removed.)
This fix won't work in Release builds (NDEBUG), so if this is concerning consider instrumenting the code at call site
Describe the issue
When using relatively new GCC (14.2.0) with globally enabled both high optimization (
-O3
) and nullptr dereference warnings (-Wnull-dereference
), the compiler issues multiple null dereferece warnings from withingtest
target.The problematic lines look as follows:
const TestSuite& test_suite = *unit_test.GetTestSuite(i);
or
test_suite.GetTestInfo(i)->is_reportable()
or
Indeed,
GetTestInfo
,GetTestSuite
,GetMutableSuiteCase
have a nullptr return path.I don't believe that there is a way to make them return a nullptr with typical usage, however the compiler can't see through this and issues a warning.
Proposed solution
Add index assertions in
GetTestInfo
,GetTestSuite
,GetMutableSuiteCase
as presented in add_assertions.patch(Please note that the patch changes the indice used in
GetTestSuite
to be more consistent with the use inGetTestSuite
andGetMutableSuiteCase
. The other reason is to avoid unused variable warning, whenindex < 0
check is removed.)This fix won't work in Release builds (
NDEBUG
), so if this is concerning consider instrumenting the code at call siteSteps to reproduce the problem
cmake -B build -G Ninja
Configure with cmakecmake --build build -t gtest
Buildgtest
targetExpected output
What version of GoogleTest are you using?
35d0c36
What operating system and version are you using?
Windows 11 24H2
What compiler and version are you using?
toolchain download link: https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-18.1.8-12.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r1.7z
What build system are you using?
Additional context
No response
The text was updated successfully, but these errors were encountered: