Commit 1b2e5099 authored by vladlosev's avatar vladlosev
Browse files

Fixes C++0x compatibility problems.

parent 2ca4d215
...@@ -98,7 +98,7 @@ class ValueArray$i { ...@@ -98,7 +98,7 @@ class ValueArray$i {
template <typename T> template <typename T>
operator ParamGenerator<T>() const { operator ParamGenerator<T>() const {
const T array[] = {$for j, [[v$(j)_]]}; const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
return ValuesIn(array); return ValuesIn(array);
} }
......
...@@ -968,23 +968,23 @@ TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) { ...@@ -968,23 +968,23 @@ TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
} }
TEST(ThreadLocalTest, GetAndPointerReturnSameValue) { TEST(ThreadLocalTest, GetAndPointerReturnSameValue) {
ThreadLocal<String> thread_local; ThreadLocal<String> thread_local_string;
EXPECT_EQ(thread_local.pointer(), &(thread_local.get())); EXPECT_EQ(thread_local_string.pointer(), &(thread_local_string.get()));
// Verifies the condition still holds after calling set. // Verifies the condition still holds after calling set.
thread_local.set("foo"); thread_local_string.set("foo");
EXPECT_EQ(thread_local.pointer(), &(thread_local.get())); EXPECT_EQ(thread_local_string.pointer(), &(thread_local_string.get()));
} }
TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) { TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
ThreadLocal<String> thread_local; ThreadLocal<String> thread_local_string;
const ThreadLocal<String>& const_thread_local = thread_local; const ThreadLocal<String>& const_thread_local_string = thread_local_string;
EXPECT_EQ(thread_local.pointer(), const_thread_local.pointer()); EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
thread_local.set("foo"); thread_local_string.set("foo");
EXPECT_EQ(thread_local.pointer(), const_thread_local.pointer()); EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
} }
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
...@@ -1094,14 +1094,15 @@ void RetrieveThreadLocalValue(pair<ThreadLocal<String>*, String*> param) { ...@@ -1094,14 +1094,15 @@ void RetrieveThreadLocalValue(pair<ThreadLocal<String>*, String*> param) {
} }
TEST(ThreadLocalTest, ParameterizedConstructorSetsDefault) { TEST(ThreadLocalTest, ParameterizedConstructorSetsDefault) {
ThreadLocal<String> thread_local("foo"); ThreadLocal<String> thread_local_string("foo");
EXPECT_STREQ("foo", thread_local.get().c_str()); EXPECT_STREQ("foo", thread_local_string.get().c_str());
thread_local.set("bar"); thread_local_string.set("bar");
EXPECT_STREQ("bar", thread_local.get().c_str()); EXPECT_STREQ("bar", thread_local_string.get().c_str());
String result; String result;
RunFromThread(&RetrieveThreadLocalValue, make_pair(&thread_local, &result)); RunFromThread(&RetrieveThreadLocalValue,
make_pair(&thread_local_string, &result));
EXPECT_STREQ("foo", result.c_str()); EXPECT_STREQ("foo", result.c_str());
} }
...@@ -1130,8 +1131,8 @@ class DestructorTracker { ...@@ -1130,8 +1131,8 @@ class DestructorTracker {
typedef ThreadLocal<DestructorTracker>* ThreadParam; typedef ThreadLocal<DestructorTracker>* ThreadParam;
void CallThreadLocalGet(ThreadParam thread_local) { void CallThreadLocalGet(ThreadParam thread_local_param) {
thread_local->get(); thread_local_param->get();
} }
// Tests that when a ThreadLocal object dies in a thread, it destroys // Tests that when a ThreadLocal object dies in a thread, it destroys
...@@ -1141,19 +1142,19 @@ TEST(ThreadLocalTest, DestroysManagedObjectForOwnThreadWhenDying) { ...@@ -1141,19 +1142,19 @@ TEST(ThreadLocalTest, DestroysManagedObjectForOwnThreadWhenDying) {
{ {
// The next line default constructs a DestructorTracker object as // The next line default constructs a DestructorTracker object as
// the default value of objects managed by thread_local. // the default value of objects managed by thread_local_tracker.
ThreadLocal<DestructorTracker> thread_local; ThreadLocal<DestructorTracker> thread_local_tracker;
ASSERT_EQ(1U, g_destroyed.size()); ASSERT_EQ(1U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]); ASSERT_FALSE(g_destroyed[0]);
// This creates another DestructorTracker object for the main thread. // This creates another DestructorTracker object for the main thread.
thread_local.get(); thread_local_tracker.get();
ASSERT_EQ(2U, g_destroyed.size()); ASSERT_EQ(2U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]); ASSERT_FALSE(g_destroyed[0]);
ASSERT_FALSE(g_destroyed[1]); ASSERT_FALSE(g_destroyed[1]);
} }
// Now thread_local has died. It should have destroyed both the // Now thread_local_tracker has died. It should have destroyed both the
// default value shared by all threads and the value for the main // default value shared by all threads and the value for the main
// thread. // thread.
ASSERT_EQ(2U, g_destroyed.size()); ASSERT_EQ(2U, g_destroyed.size());
...@@ -1170,14 +1171,14 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) { ...@@ -1170,14 +1171,14 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
{ {
// The next line default constructs a DestructorTracker object as // The next line default constructs a DestructorTracker object as
// the default value of objects managed by thread_local. // the default value of objects managed by thread_local_tracker.
ThreadLocal<DestructorTracker> thread_local; ThreadLocal<DestructorTracker> thread_local_tracker;
ASSERT_EQ(1U, g_destroyed.size()); ASSERT_EQ(1U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]); ASSERT_FALSE(g_destroyed[0]);
// This creates another DestructorTracker object in the new thread. // This creates another DestructorTracker object in the new thread.
ThreadWithParam<ThreadParam> thread( ThreadWithParam<ThreadParam> thread(
&CallThreadLocalGet, &thread_local, NULL); &CallThreadLocalGet, &thread_local_tracker, NULL);
thread.Join(); thread.Join();
// Now the new thread has exited. The per-thread object for it // Now the new thread has exited. The per-thread object for it
...@@ -1187,7 +1188,7 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) { ...@@ -1187,7 +1188,7 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
ASSERT_TRUE(g_destroyed[1]); ASSERT_TRUE(g_destroyed[1]);
} }
// Now thread_local has died. The default value should have been // Now thread_local_tracker has died. The default value should have been
// destroyed too. // destroyed too.
ASSERT_EQ(2U, g_destroyed.size()); ASSERT_EQ(2U, g_destroyed.size());
EXPECT_TRUE(g_destroyed[0]); EXPECT_TRUE(g_destroyed[0]);
...@@ -1197,12 +1198,13 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) { ...@@ -1197,12 +1198,13 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
} }
TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) { TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) {
ThreadLocal<String> thread_local; ThreadLocal<String> thread_local_string;
thread_local.set("Foo"); thread_local_string.set("Foo");
EXPECT_STREQ("Foo", thread_local.get().c_str()); EXPECT_STREQ("Foo", thread_local_string.get().c_str());
String result; String result;
RunFromThread(&RetrieveThreadLocalValue, make_pair(&thread_local, &result)); RunFromThread(&RetrieveThreadLocalValue,
make_pair(&thread_local_string, &result));
EXPECT_TRUE(result.c_str() == NULL); EXPECT_TRUE(result.c_str() == NULL);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment