As long as I have read the code and docs correctly, there isn't any explicit warning on that anywhere in the definition or docs of API, so I only found out the hard way, by trying to debug SIGSEGV occurring in our unit test runners.
After using search engine for a while, now I understand that this requirement comes from C++ standard of main() function and its argument, and possibly from your expectation that the arguments of main() are directly passed to InitGoogleTest.
According to standard, argv always contains nullptr as argc-th element, but this fact is not so well-known, and one can easily get mistaken when trying to wrap argv prior to passing to InitGoogleTest.
Does the feature exist in the most recent commit?
No
Why do we need this feature?
In your implementation of the argument parser, your code expects
argv
, passed toInitGoogleTest()
, to containnullptr
as a last element of the array (technically,argv[argc] = nullptr;
). For instance, this is the case in the following code: https://github.com/google/googletest/blob/8495449f075543dbac005d6c33118e58ad770d75/googletest/src/gtest.cc#L6657C1-L6658C70As long as I have read the code and docs correctly, there isn't any explicit warning on that anywhere in the definition or docs of API, so I only found out the hard way, by trying to debug SIGSEGV occurring in our unit test runners.
After using search engine for a while, now I understand that this requirement comes from C++ standard of
main()
function and its argument, and possibly from your expectation that the arguments ofmain()
are directly passed toInitGoogleTest
.According to standard,
argv
always containsnullptr
asargc
-th element, but this fact is not so well-known, and one can easily get mistaken when trying to wrapargv
prior to passing toInitGoogleTest
.Describe the proposal.
I propose to add a warning/note about expecting
argv
to contain a "null" element (argv[argc] = nullptr;)
after the following paragraph:https://github.com/google/googletest/blob/8495449f075543dbac005d6c33118e58ad770d75/docs/reference/testing.md?plain=1#L1320
You can also add a reference to C++ standard for reader to understand the origin of this seemingly arbitrary requirement.
Is the feature specific to an operating system, compiler, or build system version?
No, it's a standard property of C++'s
main()
function.