diff --git a/tests/test_class_release_gil_before_calling_cpp_dtor.cpp b/tests/test_class_release_gil_before_calling_cpp_dtor.cpp index c4ffca52f9..a4869a846f 100644 --- a/tests/test_class_release_gil_before_calling_cpp_dtor.cpp +++ b/tests/test_class_release_gil_before_calling_cpp_dtor.cpp @@ -10,9 +10,9 @@ namespace class_release_gil_before_calling_cpp_dtor { using RegistryType = std::unordered_map; -RegistryType &PyGILState_Check_Results() { - static auto *singleton = new RegistryType(); - return *singleton; +static RegistryType &PyGILState_Check_Results() { + static RegistryType singleton; // Local static variables have thread-safe initialization. + return singleton; } template // Using int as a trick to easily generate a series of types.