diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 78ca15d05..b29e9344b 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -666,7 +666,7 @@ namespace internal { // Points to the implicit sequence introduced by a living InSequence // object (if any) in the current thread or NULL. -GTEST_API_ extern ThreadLocal g_gmock_implicit_sequence; +GTEST_API_ ThreadLocal& GetGMockImplicitSequence(void); // Base class for implementing expectations. // @@ -1580,7 +1580,7 @@ class FunctionMocker final : public UntypedFunctionMockerBase { untyped_expectations_.push_back(untyped_expectation); // Adds this expectation into the implicit sequence if there is one. - Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); + Sequence* const implicit_sequence = GetGMockImplicitSequence().get(); if (implicit_sequence != nullptr) { implicit_sequence->AddExpectation(Expectation(untyped_expectation)); } diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index ffdf03dd4..07d11272d 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -277,7 +277,12 @@ void ExpectationBase::UntypedTimes(const Cardinality& a_cardinality) { // Points to the implicit sequence introduced by a living InSequence // object (if any) in the current thread or NULL. -GTEST_API_ ThreadLocal g_gmock_implicit_sequence; + +GTEST_API_ ThreadLocal& GetGMockImplicitSequence(void) +{ + static ThreadLocal implicit_sequence; + return implicit_sequence; +} // Reports an uninteresting call (whose description is in msg) in the // manner specified by 'reaction'. @@ -768,8 +773,8 @@ void Sequence::AddExpectation(const Expectation& expectation) const { // Creates the implicit sequence if there isn't one. InSequence::InSequence() { - if (internal::g_gmock_implicit_sequence.get() == nullptr) { - internal::g_gmock_implicit_sequence.set(new Sequence); + if (internal::GetGMockImplicitSequence().get() == nullptr) { + internal::GetGMockImplicitSequence().set(new Sequence); sequence_created_ = true; } else { sequence_created_ = false; @@ -780,8 +785,8 @@ InSequence::InSequence() { // of this object. InSequence::~InSequence() { if (sequence_created_) { - delete internal::g_gmock_implicit_sequence.get(); - internal::g_gmock_implicit_sequence.set(nullptr); + delete internal::GetGMockImplicitSequence().get(); + internal::GetGMockImplicitSequence().set(nullptr); } }