diff --git a/cpp/src/base/singleton.h b/cpp/src/base/singleton.h index a8fb23bed..4030e4212 100644 --- a/cpp/src/base/singleton.h +++ b/cpp/src/base/singleton.h @@ -31,7 +31,7 @@ class Singleton : private boost::noncopyable { static T* GetInstance() { boost::call_once(Init, flag); - return instance; + return instance.get(); } private: @@ -43,7 +43,7 @@ class Singleton : private boost::noncopyable { static boost::once_flag flag; }; -template boost::scoped_ptr Singleton::instance = NULL; +template boost::scoped_ptr Singleton::instance; template boost::once_flag Singleton::flag = BOOST_ONCE_INIT; } // namespace phonenumbers diff --git a/cpp/src/phonenumberutil.h b/cpp/src/phonenumberutil.h index 3776515cb..37f820c91 100644 --- a/cpp/src/phonenumberutil.h +++ b/cpp/src/phonenumberutil.h @@ -62,9 +62,12 @@ class PhoneNumberUtil { friend struct DefaultSingletonTraits; #else class PhoneNumberUtil : public Singleton { + friend class Singleton; #endif friend class PhoneNumberUtilTest; public: + ~PhoneNumberUtil(); + // INTERNATIONAL and NATIONAL formats are consistent with the definition // in ITU-T Recommendation E. 123. For example, the number of the Google // Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL @@ -533,7 +536,6 @@ class PhoneNumberUtil : public Singleton { scoped_ptr > region_to_metadata_map_; PhoneNumberUtil(); - ~PhoneNumberUtil(); // Gets all the supported regions. void GetSupportedRegions(set* regions) const; diff --git a/cpp/src/phonenumberutil_test.cc b/cpp/src/phonenumberutil_test.cc index fcb22f896..9595ca952 100644 --- a/cpp/src/phonenumberutil_test.cc +++ b/cpp/src/phonenumberutil_test.cc @@ -248,6 +248,10 @@ ostream& operator<<(ostream& os, const PhoneNumber& number) { return os; } +TEST_F(PhoneNumberUtilTest, GetInstance) { + EXPECT_FALSE(PhoneNumberUtil::GetInstance() == NULL); +} + TEST_F(PhoneNumberUtilTest, GetSupportedRegions) { set regions;