[Bug]: Threadsafe death tests pass without running when the test name contains ':' (e.g. typed test named "std::string")
Describe the issue
In the "threadsafe" death test style (and always on Windows and Fuchsia), the parent re-executes the test binary and selects the current test with --gtest_filter=<suite>.<name>, built from the raw test name (gtest-death-test.cc, around lines 1372, 778 and 972). The name is not escaped, but filter syntax treats : as a pattern separator and - as the start of negative patterns. (* and ? are wildcards too, but in my testing a name containing them still matches itself, so those death tests run normally.)
Test names can legitimately contain these characters. Typed-test name generators aren't restricted (a generator returning "std::string" is natural), and neither are names passed to RegisterTest.
When the name contains : or -, the child's filter matches no test. The child prints WARNING: filter "..." did not match any test; no tests were run and exits with status 0 without writing a status byte. DeathTestImpl::ReadAndInterpretStatusByte then treats the missing byte as DIED (around line 482). As a result:
- a death test whose statement does not die passes without the statement ever running;
- a correct death test such as
EXPECT_EXIT(_exit(1), ExitedWithCode(1), "")fails withdied but not with expected exit code: Exited with exit status 0.
The same tests instantiated for a type named int behave correctly.
Expected: the death test runs its statement in the child regardless of the characters in the test name. Separately, a child that exits without reaching the death test statement should probably be reported as an error, not as DIED.
Steps to reproduce the problem
#include <string>
#include <unistd.h>
#include "gtest/gtest.h"
template <typename T> class TT : public ::testing::Test {};
struct Names {
template <typename T> static std::string GetName(int) {
return std::is_same<T, std::string>::value ? "std::string" : "int";
}
};
using Types = ::testing::Types<int, std::string>;
TYPED_TEST_SUITE(TT, Types, Names);
TYPED_TEST(TT, DoesNotExit) {
// Does not exit, so this should fail with "failed to die".
EXPECT_EXIT({ fprintf(stderr, "child ran statement\n"); },
::testing::ExitedWithCode(0), "");
}
TYPED_TEST(TT, Exits1) {
EXPECT_EXIT(_exit(1), ::testing::ExitedWithCode(1), "");
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
return RUN_ALL_TESTS();
}Built with g++ -std=c++17 repro.cc -lgtest -pthread. Output (trimmed):
[ RUN ] TT/int.DoesNotExit
Result: failed to die.
[ FAILED ] TT/int.DoesNotExit, where TypeParam = int
[ RUN ] TT/int.Exits1
[ OK ] TT/int.Exits1
[ RUN ] TT/std::string.DoesNotExit
WARNING: filter "TT/std::string.DoesNotExit" did not match any test; no tests were run
[ OK ] TT/std::string.DoesNotExit
[ RUN ] TT/std::string.Exits1
WARNING: filter "TT/std::string.Exits1" did not match any test; no tests were run
Result: died but not with expected exit code:
[ FAILED ] TT/std::string.Exits1, where TypeParam = std::basic_string<...>TT/std::string.DoesNotExit passes even though its statement never ran.
What version of GoogleTest are you using?
main at 4267679 (2026-09-17)
What operating system and version are you using?
Ubuntu 24.04.4 LTS (Linux x86_64). By code inspection, Windows and Fuchsia are affected in the default death test style, since they always re-execute the binary.
What compiler and version are you using?
g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
What build system are you using?
cmake version 3.28.3
Additional context
Possible fixes:
- When
--gtest_internal_run_death_testis set, have the child select its test by exact full name instead of through--gtest_filterpattern matching. For example, pass the exact name in the internal flag, or bypass pattern parsing for it. - Alternatively, escape the filter's special characters, or reject them in typed-test and
RegisterTestnames like parameterized-test names already are. - Independently, the parent could treat a child that exits without writing a status byte as an internal error rather than
DIED.
I'm happy to send a PR once there's agreement on the approach.
Source: google/googletest