diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 7be0caaf..e4c414c2 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1112,10 +1112,11 @@ class GTEST_API_ TestEventListeners { // according to their specification. class GTEST_API_ UnitTest { public: + friend std::default_delete; // Gets the singleton UnitTest object. The first time this method // is called, a UnitTest object is constructed and returned. // Consecutive calls will return the same object. - static UnitTest* GetInstance(); + static std::unique_ptr& GetInstance(); // Runs all tests in this UnitTest object and prints the result. // Returns 0 if successful, or 1 otherwise. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 09af1517..fc211ab3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5243,22 +5243,9 @@ void TestEventListeners::SuppressEventForwarding(bool suppress) { // Gets the singleton UnitTest object. The first time this method is // called, a UnitTest object is constructed and returned. Consecutive // calls will return the same object. -// -// We don't protect this under mutex_ as a user is not supposed to -// call this before main() starts, from which point on the return -// value will never change. -UnitTest* UnitTest::GetInstance() { - // CodeGear C++Builder insists on a public destructor for the - // default implementation. Use this implementation to keep good OO - // design with private destructor. - -#if defined(__BORLANDC__) - static UnitTest* const instance = new UnitTest; +std::unique_ptr& UnitTest::GetInstance() { + static std::unique_ptr instance{ new UnitTest }; return instance; -#else - static UnitTest instance; - return &instance; -#endif // defined(__BORLANDC__) } // Gets the number of successful test suites.